Page 133 - TP_Plus_v4_Class7
P. 133

Program 4: To display one of the two alternate messages

                     Program4.py
                  File  Edit  Format   Run   Options   Window    Help

                  #Program to display one of two alternate massages
                  passing_score = 60
                  my_score = int(input('Enter a score: '))
                  if(my_score >= passing_score):
                      print('congratulations on passing the exam')
                  else:
                      print('You failed, try harder next time')





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

                     Output
                  Enter a score: 78
                  Congratulations on passing the exam


                  Enter a score: 45
                  You failed, try harder next time







                          Double Tap                                                  Century   #Technology Literacy
                                                                                        21 st
                                                                                           #Critical Thinking
                                                                                       Skills
                        Find the error in the following code and rewrite the code:

                        if(age > 18)
                        print(‘You are eligible to vote’)
                        else:
                        print(‘Not eligible to vote’)











                 Nested if Statement

                 You can also nest if statements within other if statements to create more complex decision-making
                 logic. 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.






                                                                                    #Conditional Statements in Python 131
   128   129   130   131   132   133   134   135   136   137   138