Page 149 - 2620_Birla Open Mind C-7
P. 149

Program 1: To check whether a given number is positive

                     Program1.py
                  File  Edit  Format   Run   Options   Window     Help

                  #Program to check if a number is positive

                  n = int (input ('Enter a number:'))
                  if(n > 0):
                      print('Entered number is positive')


                  #Statement outside the if statement
                  print('All numbers greater than 0 are positive')



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

                     Output

                  Enter a number:6
                  Entered number is positive
                  All numbers greater than 0 are positive


                  Enter a number:-9
                  All numbers greater than 0 are positive




                 Program 2: To demonstrate the if statement

                     Program2.py
                  File  Edit  Format   Run   Options   Window     Help

                  #Program to display the message using if statement
                  days = int(input('How many days are there in a leap year?'))


                  if(days == 366):
                      print('Your answer is correct, Good Job')




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

                     Output

                  How many days are there in a leap year? 366
                  Your answer is correct, Good Job


                  How many days are there in a leap year? 365






                                                                                    #Conditional Statements in Python 147
   144   145   146   147   148   149   150   151   152   153   154