Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 84 - 2615_KEC
P. 84

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

                          Program4.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!!!')

                          Output

                       Enter the first number: 84
                       Grade A

                      THE NESTED if STATEMENTS
                      Nested if statements mean if statements are                Start
                      placed  within  another if  statement.  Python
                      allows us to  write  an if statement  within
                      another if statement. The syntax of the nested                         False     Statement 3
                      if statement is as follows:                             if condition 1
                      if (conditional expression1):
                                                                                    True
                          statement(s)
                          if (conditional expression2):                       if condition 2  False    Statement 2
                                  statement(s)
                          elif (conditional expression3):
                                  statement(s)                                       True
                          else:                                               Statement 1
                                  statement(s)
                      else:
                          statement(s)                                           Stop

                       82   Premium Edition-VIII

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