Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 140 - 2612_Digimind
P. 140

    elif (conditional expression):
                                  statement(s)

                          else:
                                  statement(s)

                      Program 3: To grade a student according to his/her marks

                          Program3.py
                       File  Edit  Format    Run   Options   Window    Help

                       #Program to grade a student according to his/her marks

                       marks = int(input('Enter marks: '))
                       if(marks >=90):
                           print('Grade A+')
                       elif(marks >=80):

                           print('Grade A')
                       elif(marks >=70):
                           print('Grade B+')
                       elif(marks >=60):

                           print('Grade B')
                       elif(marks >=50):
                           print('You can do better!!!')
                       else:

                           print('You need to work hard!!!')

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

                          Output

                       Enter the first number: 84
                       Grade A

                      THE NESTED if STATEMENTS

                      Nested if statements mean if statements are placed within another if statement. Python allows
                      us to write an if statement within another if statement. The syntax of the nested if statement is as
                      follows:

                      138   Premium Edition-VII

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