Page 62 - Computer - 7
P. 62

2. Press the F5 key to execute the code. Sample outputs of the program are given below.



                                                                 Start
                                                                                                     Is
                                                               Input Number                      Test Condi  on 1  No
                                                                  N                                 True?

                                                                  Is  No                              Yes
                                                                    N > 0 ?
                                                                  Yes                         No     Is      Execute
                                                                                                 Test Condi  on 1  else block
                                                                Print N is   Print N is             True?
          IF … ELIF … ELSE LADDER                               Posi  ve    Nega  ve                  Yes
                                                                 Stop
          The if … elif … else ladder is used to test several conditions one after the other in a top-down approach,
                                                                                                   Execute
                                                                                                   if block
          starting from the top-most condition. If the test condition associated with any If statement evaluates to
          True, the set of blocks under it are executed, otherwise the execution
                                                                  Is
          passes to the set of statements after the corresponding if statement.
                                                                       Yes
                                                                            Execute
                                                               Test Condi  on
                                                                 True?      if block                 Is   Yes  Execute
          The syntax for using the if … elif … else statement is:  No                            Test Condi  on 1  if block 3
                                                                                                    True?
                 if <test condition 1>:                                                               No
                   set of statements 1                                                  Execute      Is       Execute
                                                                                        if block 3  Yes  Test Condi  on 2  Yes  if block 3
                                                                                                    True?
                 elif <test condition 2>:
                   set of statements 2                                                                No
                                                                 Is    Yes  Execute
                 elif <test condition 3>:                     Test Condi  on  if block           Test Condi  on 3
                                                                                                     Is
                                                                True?
                                                                                                    True?
                   set of statements 3                            No
                                                                                                     No
                                                                Execute
                 else:                                         else block                          Execute
                                                                                                   else block
                   set of statements under else
                 other statements
                                                                                                                         64


            Lab Activity 4
                                                                                                   Experiential Learning
           Program to calculate and display the discount and net amount payable by a customer.

           The program accepts the name of the customer and bill amount for purchases made. The discount
           given to the customer depends on the bill amount as per the following criteria:
             •  If the bill amount is above ` 25000, the discount percentage is 20%.

             •   If the bill amount is from ` 20000 - ` 25000, the discount percentage is 15%.

             •  If the bill amount is from ` 10000 - ` 20000, the discount percentage is 10%.

             •  If the bill amount is from ` 5000 - ` 10000, discount percentage is 5%.
             •  If the bill amount is below ` 5000, no discount is given.





               60
   57   58   59   60   61   62   63   64   65   66   67