Professional Documents
Culture Documents
Lec 1
Lec 1
Computer Programming
(2)
Lec 01: Revision (1)
Variables
Data Types
Type Example Usage
int x = 20 Integer numbers
if condition:
statements to execute if
condition is True
else:
statements to execute if
condition is False
4/10/2022 Computer Programming (2) 13
Extending if-else blocks
if condition_1:
statements to execute if
condition_1 is True
elif condition_2:
statements to execute if
condition_2 is True
elif condition_n:
statements to execute if
condition_n is True
else:
statements to execute if
all above conditions are False
• elif = else + if which means that the previous statements must be false for the current one to evaluate to
true
4/10/2022 Computer Programming (2) 14
Example
• Calculate income tax for the given income according to the following
rules:
while condition:
perform a certain process