Page 104 - TP_Play_V2.1_class7
P. 104

NESTED IF STATEMENT

                  Python allows the  nested if statement. This means that  you have an if statement  inside
                  another  if statement.  The inner  if block will run only when  the first if condition evaluates
                  to true.

                  The syntax of nested if statement is shown below:
                  Syntax:                                                    Start

                  if (Test Expression1):
                       if (Test Expression2):
                                                                                          False
                                                                         if condition 1              block 3
                            Indented block 1
                       else:
                                                                                True
                            Indented block 2
                                                                                          False
                  else:
                                                                          if condition 2             block 2
                       Indented block 3
                  Program  5:  To  find  out  if the  student  is                True
                  selected for the college or not based on the              block 1
                  given conditions–

                  1.  Selected if age > 18 and marks > 65
                                                                             Stop
                  2.  Not selected if age > 18 and marks < 65
                  3.  Not selected if age < 18

                      Program5.py

                   File  Edit  Format    Run   Options   Window    Help

                   #Program to check if a student is selected for college or not
                   name = input('Enter the name of the student: ')
                   age = int(input('Enter the age of the student: '))
                   marks = int(input('Enter the marks of the student: '))
                   if(age > 18):
                       if(marks > 65):
                           print(name, 'is selected for college')
                       else:
                           print(name, 'is not selected for college')
                   else:
                       print(name, 'is too young for college')

















                  102       Play (Ver. 2.1)-VII
   99   100   101   102   103   104   105   106   107   108   109