Page 101 - Trackpad_V2.1_class8
P. 101

SOME MORE PROGRAMS


                 Program 11: To test whether a given number is even or odd
                     Program11.py

                  File  Edit  Format   Run    Options   Window    Help

                  #Program to check whether the number is even or odd
                  number = int(input("Enter an integer: "))
                  if number % 2 == 0:
                      print("The number is even.")
                  else:
                      print("The number is odd.")




                 On running the above program, we get the following output:
                     Output

                  Enter an integer: 24
                  The number is even.



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

                     Program12.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.")




                 On running the above program, we get the following output:

                     Output

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





                                                                                        Control Structures in Python  99
   96   97   98   99   100   101   102   103   104   105   106