Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 125 - 2615_KEC
P. 125

    Program 28: To determine the weather is hot, warm, cool or cold based on given temperature.

                         Program28.py
                      File  Edit  Format   Run    Options   Window    Help

                      #Program to determine the weather is hot, warm, cool or cold based on given
                      temperature.
                      temperature = float(input("Enter the temperature in Celsius: "))
                      if temperature > 30:
                          print("It's hot outside.")
                      elif temperature > 20:
                          print("It's warm outside.")
                      elif temperature > 10:
                          print("It's cool outside.")
                      else:
                          print("It's cold outside.")

                         Output

                      Enter the temperature in Celsius: 15
                      It's cool outside.

                     Program 29: To create a ticket vending simulation. If the age of a person lies between 10 to 20
                     years, the price of the ticket will be Rs. 200. If the age of a person lies between 20 to 60 years, the
                     price of the ticket will be Rs. 350. If the age of a person is greater than 60 years then the price of
                     the ticket will be Rs. 300.

                         Program29.py

                      File  Edit  Format   Run    Options   Window    Help

                      # Ticket Vending Machine
                      # Price of ticket is Rs. 200 is age is between 10 to 20.
                      # Price of ticket is Rs. 350 is age is between 20 to 60.
                      # Price of ticket is Rs. 300 is age is greater than 60.
                      age = int(input("Enter your age: "))
                      if (age>10 and age<20):
                          print("The price of the ticket is Rs. 200.")
                      elif (age>20 and age<60):
                          print("The price of the ticket is Rs. 350.")
                      elif (age>60):
                          print("Ihe price of the ticket is Rs. 300.")
                      else:
                          print("No need of ticket.")

                                                                                            Control Structures in Python  123

| 120 121 122 123 124 125 126 127 128 129 130 |