Introduction to Python
Form 3 - Computer
2023-2024
Floor 4 - Computer Room
Mr. Peter
Outline
Outline
If statement review
![](https://s3.amazonaws.com/media-p.slid.es/uploads/2214875/images/9811262/pasted-from-clipboard.png)
1
And/Or Condition
2
Exercises
3
If statements
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1490014/images/9343467/pasted-from-clipboard.png)
if :
1.
2.
Command1
Tab
if Condition :
Command1
![](https://s3.amazonaws.com/media-p.slid.es/uploads/2214875/images/10323234/pasted-from-clipboard.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/2214875/images/10323269/pasted-from-clipboard.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/2214875/images/10323234/pasted-from-clipboard.png)
False
True
Condition is like a door that controls opening and closing.
If else statements
else:
Command2
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1490014/images/9343467/pasted-from-clipboard.png)
if Condition :
1.
2.
3.
4.
Command1
Tab
Tab
![](https://s3.amazonaws.com/media-p.slid.es/uploads/2214875/images/10323234/pasted-from-clipboard.png)
False
If the door is closed
It will execute command2
If elif else statements
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1490014/images/9343467/pasted-from-clipboard.png)
if Condition :
1.
2.
3.
4.
Tab
Tab
elif Condition :
else:
Command3
Tab
Command2
Command1
5.
6.
![](https://s3.amazonaws.com/media-p.slid.es/uploads/2214875/images/10323234/pasted-from-clipboard.png)
False
![](https://s3.amazonaws.com/media-p.slid.es/uploads/2214875/images/10323234/pasted-from-clipboard.png)
False
Input function
Same
Differrent
1.
2.
int(
input( "Prompt message: " )
user =
)
user = int( input("Prompt message: ") )
Same
Differrent
1.
2.
You are tasked with implementing a program to evaluate a student's grade based on their scores in different subjects. The program should consider the scores in individual subjects and determine the overall grade based on certain criteria.
The program should do the following:
1.
Question
Create variables to store the scores of three subjects: math_score
, science_score
, and english_score
.
2.
Require the user to input their scores for these subjects.
3.
Use if statements with AND
and OR
operators to check the following conditions:
If elif else statement - Ex01
Save the file as "XX_YYYY_Ex01.py"
- A student passes if they score at least 60
in each subject.
- A student fails if they score less than 35
in any subject.
Same
Differrent
1.
2.
You are tasked with implementing a program to evaluate a student's grade based on their scores in different subjects. The program should consider the scores in individual subjects and determine the overall grade based on certain criteria.
The program should do the following:
1.
Question
Create variables to store the scores of three subjects: math_score
, science_score
, and english_score
.
2.
Require the user to input their scores for these subjects.
3.
Use if statements with AND
and OR
operators to check the following conditions:
If elif else statement - Ex01
Save the file as "XX_YYYY_Ex01.py"
- A student passes if they score at least 60
in each subject.
Same
Differrent
1.
2.
The if
statement with and
/or
operators is used to determine whether it's a good day for swimming based on the temperature and whether it is summer or not. Based on the inputs provided by the user, the program indicates either a great day for swimming, nice weather but not for swimming, or the temperature is too cold for swimming.
The program should do the following:
1.
Question
The question should involve creating two variables named temperature
and is_summer
.
If elif else statement - Ex02
Save the file as "XX_YYYY_Ex01.py"
2.
Students should be prompted to input the current temperature and whether it is summer (yes/no).
3.
The scenario for the if statement should be related to deciding whether to go for a swim.
4.
Use an if
statement with and
/or
operators to check the following scenarios:
-
If the temperature is above 25 degrees and it is summer, print "Great day for a swim!"
-
If the temperature is above 25 degrees but it's not summer, print "Nice weather, but not for swimming!"
-
If the temperature is 25 degrees or below, print "It's too cold for swimming."
Same
Differrent
1.
2.
the if
statement with and
/or
operators is used to determine whether it's a good day for swimming based on the temperature and whether it is summer or not. Based on the inputs provided by the user, the program indicates either a great day for swimming, nice weather but not for swimming, or the temperature is too cold for swimming.
The program should do the following:
1.
Question
The question should involve creating two variables named temperature
and is_summer
.
If elif else statement - Ex02
Save the file as "XX_YYYY_Ex01.py"
2.
Students should be prompted to input the current temperature and whether it is summer (yes/no).
3.
The scenario for the if statement should be related to deciding whether to go for a swim.
4.
Use an if
statement with and
/or
operators to check the following scenarios:
-
If the temperature is above 25 degrees and it is summer, print "Great day for a swim!"
-
If the temperature is above 25 degrees but it's not summer, print "Nice weather, but not for swimming!"
-
If the temperature is 25 degrees or below, print "It's too cold for swimming."
Same
Differrent
1.
2.
the if
statement with and
/or
operators is used to determine whether it's a good day for swimming based on the temperature and whether it is summer or not. Based on the inputs provided by the user, the program indicates either a great day for swimming, nice weather but not for swimming, or the temperature is too cold for swimming.
The program should do the following:
1.
Question
The question should involve creating two variables named temperature
and is_summer
.
If elif else statement - Ex02
Save the file as "XX_YYYY_Ex02.py"
2.
Students should be prompted to input the current temperature and whether it is summer (yes/no).
3.
The scenario for the if statement should be related to deciding whether to go for a swim.
4.
Use an if
statement with and
/or
operators to check the following scenarios:
-
If the temperature is above 25 degrees and it is summer, print "Great day for a swim!"
-
If the temperature is above 25 degrees but it's not summer, print "Nice weather, but not for swimming!"
-
If the temperature is 25 degrees or below, print "It's too cold for swimming."
Same
Differrent
1.
2.
You are tasked with creating a program to calculate the bonus amount for employees based on their performance and years of service. The program should decide the bonus amount according to specific conditions.
The program should do the following:
1.
Question
Create variables performance_rating
(1-5) and years_of_service
to store the performance rating and the years of service of the employee.
If elif else statement - Bonus
Save the file as "XX_YYYY_Ex02.py"
- If an employee's performance rating is
4
or5
and they have at least5
years of service, they receive a bonus of10%
of their salary.
2.
Require the user to input their performance rating and years of service.
3.
Use if statements with AND
and OR
operators to check the following conditions:
- If an employee's performance rating is
3
and they have at least3
years of service, they receive a bonus of5%
of their salary.
-
No Bonus
will be given if they do not satisfy any of the requirements listed above.
Same
Differrent
1.
2.
You are tasked with creating a program to calculate the bonus amount for employees based on their performance and years of service. The program should decide the bonus amount according to specific conditions.
The program should do the following:
1.
Question
Create variables performance_rating
(1-5) and years_of_service
to store the performance rating and the years of service of the employee.
If elif else statement - Bonus
Save the file as "XX_YYYY_Bonus.py"
- If an employee's performance rating is
4
or5
and they have at least5
years of service, they receive a bonus of10%
of their salary.
2.
Require the user to input their performance rating and years of service.
3.
Use if statements with AND
and OR
operators to check the following conditions:
- If an employee's performance rating is
3
and they have at least3
years of service, they receive a bonus of5%
of their salary.
-
No Bonus
will be given if they do not satisfy any of the requirements listed above.
Python - if and or statement 02
By Mr Peter
Python - if and or statement 02
- 251