Page 109 - Trackpad_V1_Book 8_Flipbook
P. 109

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

























                 You will get the following output:




















                 THE NESTED if STATEMENTS
                 Nested if statements means 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:

                 if (conditional expression):
                     statement(s)
                                                                  Test        False       Nested test
                     if (conditional expression2):             expression                 expression
                                                                   1
                             statement(s)                                                                       False
                                                                     True                         True
                     elif (conditional expression3):

                             statement(s)                      Body of else                 Body of         Body of
                                                                                            nested if     nested else
                     else:

                             statement(s)
                 else:                                        Statement just
                                                                 below if
                     statement(s)






                                                                                        Control Structures in Python  107
   104   105   106   107   108   109   110   111   112   113   114