Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 89 - 2615_KEC
P. 89

    Output
                      Number is: 0
                      Number is: 1
                      Number is: 2
                      Number is: 3
                      Number is: 4
                      Number is: 5
                      Number is: 6
                      Number is: 7
                      Number is: 9
                      Number is: 10
                      Number is: 11
                      Out of loop

                     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 12: To test whether a given number is even or odd.

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

                         Output

                      Enter an integer: 24
                      The number is even.

                     Program 13: 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.

                                                                                                       Flow of Control  87

| 84 85 86 87 88 89 90 91 92 93 94 |