Page 48 - Code & Click - 7
P. 48
Start
Is
Input Number
True?
Yes
Is N No Test Condi on 1 No
N > 0 ?
Yes No Is Execute
Test Condi on 1 else block
Print N is Print N is True?
Posi ve Nega ve
IF … ELIF … ELSE LADDER Yes
Stop Execute
The if … elif … else ladder is used to test several conditions one after the other in a top-down approach,
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 passes to the set of statements after the corresponding
Is
Execute
Yes
Test Condi on
if block
if statement. True? Test Condi on 1 Yes if block 3
Is
Execute
True?
No
The syntax for using the if … elif … else statement is:
No
if <test condition 1>:
Is
set of statements 1 Execute Yes Test Condi on 2 Yes Execute
if block 3
True? if block 3
elif <test condition 2>:
No
set of statements 2 Is
Test Condi on Yes Execute Is
if block
elif <test condition 3>: True? Test Condi on 3
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.
1. Type the code as shown in the image in the Python Editor.
46