Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 85 - 2615_KEC
P. 85

    Program 5: To determine which number is greater among three numbers.

                         Program5.py
                      File  Edit  Format   Run    Options   Window    Help

                      #Program to determine which number is greater among three numbers
                      num1 = int(input('Enter the First Number: '))
                      num2 = int(input('Enter the Second Number: '))
                      num3 = int(input('Enter the Third Number: '))
                      if(num1>num2):
                          if(num1>num3):
                              print('First number is the greatest number.')
                          else:
                              print('Third number is the greatest number.')
                      else:
                          if(num2>num3):
                              print('Second number is the greatest number.')
                          else:
                              print('Third number is the greatest number.')

                         Output

                      Output: Enter the First Number: 12
                      Enter the Second Number: 45
                      Enter the Third Number: 23
                      Second number is the greatest number.

                               ITERATIVE STATEMENTS

                     Iterative statements refer to the statements that are used to repeat a task based on a given

                     condition. These statements are also known as looping statements. An iteration means one pass
                     of a loop.
                     Python provides the following iterative statements:

                     (i)  For loop                   (ii)  While loop

                     THE for LOOP

                     The for loop is a type of iterative statement that allows the user to repeat a set of statements multiple
                     times until a given condition is falsified. The for loop is commonly used when the number of iterations
                     is known in advance or when iterating over a sequence, such as a list, string, tuple, or a range."

                                                                                                       Flow of Control  83

| 80 81 82 83 84 85 86 87 88 89 90 |