Introduction to Python
Floor 4 - Computer Room
Outline
Outline
If statement review
1
And/Or Condition
2
Exercises
3
If statements
if :
1.
2.
Command1
Tab
if Condition :
Command1
False
True
Condition is like a door that controls opening and closing.
If else statements
else:
Command2
if Condition :
1.
2.
3.
4.
Command1
Tab
Tab
False
If the door is closed
It will execute command2
If elif else statements
if Condition :
1.
2.
3.
4.
Tab
Tab
elif Condition :
else:
Command3
Tab
Command2
Command1
5.
6.
False
False
Input function
Same
Differrent
1.
2.
int(
input( "Prompt message: " )
user =
)
user = int( input("Prompt message: ") )
Same
Differrent
1.
2.
Write a Python code snippet that checks whether a given number is positive or negative.
The program should do the following:
1.
Question
Prompt the user to enter a number.
2.
Check whether the number is positive, negative, or zero.
3.
Print an appropriate message depending on the result of the check.
If elif else statement - Ex08_1
Save the file as "XX_YYYY_Ex08_1.py"
Same
Differrent
1.
2.
Write a Python code snippet that takes in a student's score and calculates their final grade based on the following requirements.
The program should do the following:
1.
Question
Prompt the user to enter a score
2.
If the average score is greater than or equal to 80, the student gets an A.
3.
If the average score is greater than or equal to 60 but less than 80, the student gets a B.
4.
If the average score is less than 60, the student gets an C.
5.
Print an appropriate grade depending on the result of the check.
If elif else statement - Ex08_2
Save the file as "XX_YYYY_Ex08_2.py"
Same
Differrent
1.
2.
Write a Python code snippet that takes in a student's score and calculates their final grade based on the following requirements.
Question
If elif else statement - Ex08_2
A
B
C
Save the file as "XX_YYYY_Ex08_2.py"
If elif else statement - Ex08_3
Same
Differrent
1.
2.
Write a Python code that implements the discount calculator.
The program should do the following:
1.
Question
Prompt the user to enter a pricing number.
2.
10% discount for purchases of $100 or more
3.
20% discount for purchases of $200 or more
4.
30% discount for purchases of $300 or more
5.
Print how much does the user need to pay?
Save the file as "XX_YYYY_Ex08_3.py"
Same
Differrent
1.
2.
Write a Python code that implements the discount calculator.
Question
30% discount
20% discount
10% discount
No discount
If elif else statement - Ex08_3
Save the file as "XX_YYYY_Ex08_3.py"