Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 104 - 2607_Trackpad_Pro_5.1_flipbook_C7
P. 104

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

                         Output

                      Enter the first number: 84
                      Grade A

                     THE NESTED if STATEMENTS                                  Start

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

                                                                                            Control Structures in Python  103

| 99 100 101 102 103 104 105 106 107 108 109 |