Page 60 - Computer - 7
P. 60

Lab Activity 1                                                                         Start
                                                                                                   Experiential Learning
                                                                                                                                               Is
           Program to accept a number from the user and display if the number is positive.  Input Number                                   Test Condi  on 1  No
           1. Type the code as shown in the image in the Python Editor.                             N                                         True?

                                                                                                                                                Yes
                                                                                                    Is  No
                                                                                                  N > 0 ?

                                                                                                    Yes                                No      Is         Execute
                                                                                                                                           Test Condi  on 1  else block
                                                                                                  Print N is    Print N is                    True?
                                                                                                  Posi  ve      Nega  ve
                                                                                                                                                Yes
                                                                                                   Stop
           2. Press the F5 key to execute the code. Sample output of the program is given below.                                             Execute
                                                                                                                                              if block





                                                                                                   Is
                                                                                                Test Condi  on  Yes  Execute
                                                                                                  True?          if block                      Is
                                                                                                                                                           Execute
                                                                                                                                           Test Condi  on 1  Yes  if block 3
                                                                                                                                              True?
                                                                                                    No
                                                                                                                                                No
          IF… ELSE STATEMENT
          The if … else statement is used to evaluate a test condition and to perform two distinct tasks depending              Execute  Yes  Test Condi  on 2  Yes  Execute
                                                                                                                                                Is
          on the result of the test condition. If the test condition evaluates to True, the block of statements under          if block 3     True?        if block 3
          if is executed. If the test condition evaluates to False, the block of statements
          under else is executed. After the execution of either of the two blocks of                                                            No
          statements, the control passes to the statement after the else block.                    Is     Yes  Execute
                                                                                                                                                Is
          The syntax for using the if statement is:                                            Test Condi  on  if block                    Test Condi  on 3
                                                                                                  True?
                 if <test condition>:                                                                                                         True?
                   set of statements under if                                                       No                                          No
                                                                                                 Execute
                 else:                                                                           else block
                                                                                                                                              Execute
                   set of statements under else                                                                                              else block
                 other statements


            Lab Activity 2                                                                                                                                              64
           Program to input age of user and display whether the user is eligible to vote or not.   Experiential Learning
           1. Type the code as shown in the image in the Python Editor.



















               58
   55   56   57   58   59   60   61   62   63   64   65