Page 103 - trackpad v5.1 class 8 flipbook
P. 103

The example above prints all the numbers except 8 because when the value of number is equal
                 to 8, the continue statement placed inside the if statement will force the program to skip the
                 iteration.



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









                                                                                        Control Structures in Python  101
   98   99   100   101   102   103   104   105   106   107   108