Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 141 - 2612_Digimind
P. 141

    if (conditional expression1):
                                                                               Start
                         statement(s)

                         if (conditional expression2):
                                                                                            False
                                 statement(s)                                if condition 1           Statement 3
                         elif (conditional expression3):
                                                                                   True
                                 statement(s)
                                                                                            False
                         else:                                               if condition 2           Statement 2
                                 statement(s)

                     else:                                                         True
                         statement(s)                                        Statement 1

                                                                                Stop
                     Program 4: To determine which number is greater among three numbers

                         Program4.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                             Just as the heart repeatedly pumps
                                                                                       blood, iteration in programming
                      Enter the Second Number: 45
                                                                                     involves repeatedly running a set of
                      Enter the Third Number: 23
                                                                                                instructions.
                      Second number is the greatest number.

                                                                                            Control Structures in Python  139

| 136 137 138 139 140 141 142 143 144 145 146 |