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
And/Or Condition
Same
Differrent
1.
2.
if Condition1
And condition: All conditions need to be True
![](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/10323269/pasted-from-clipboard.png)
Command
True
True
and
Condition2:
And/Or Condition
Same
Differrent
1.
2.
if Condition1
Or condition: Either one of the condition is True
![](https://s3.amazonaws.com/media-p.slid.es/uploads/2214875/images/10323269/pasted-from-clipboard.png)
Command
True
False
or
Condition2:
![](https://s3.amazonaws.com/media-p.slid.es/uploads/2214875/images/10323234/pasted-from-clipboard.png)
If And/Or statement - 01
Same
Differrent
1.
2.
Write a Python program to determine whether a person's age is a teenage, which is defined as an age range between 12 to 18 (inclusive).
The program should do the following:
1.
Question
Assign a value for age variable.
2.
Check if the age is between 12 to 18 (inclusive)
3.
If the age is within the teenage range, the program should print "You are a teenager!".
4.
If the age is not within the teenage range, the program should print "Sorry, you are not a teenager!"
Save the file as "XX_YYYY_01.py"
If And/Or statement - 01
Same
Differrent
1.
2.
Write a Python program to determine whether a person's age is a teenage, which is defined as an age range between 12 to 18 (inclusive).
Question
Save the file as "XX_YYYY_01.py"
If And/Or statement - 02
Same
Differrent
1.
2.
Write a Python program to determine whether a student's score is invalid, which is defined as a score less than 0 or greater than 100.
The program should do the following:
1.
Question
Assign a value for the score variable.
2.
Check if the score is less than 0 or greater than 100.
3.
If the score is invalid, the program should print "Invalid score!"
4.
If the score is valid, the program should print "Score is valid."
Save the file as "XX_YYYY_02.py"
If And/Or statement - 02
Same
Differrent
1.
2.
Write a Python program to determine whether a student's score is invalid, which is defined as a score less than 0 or greater than 100.
Question
Save the file as "XX_YYYY_02.py"
If And/Or statement - 03
Same
Differrent
1.
2.
Write a Python program to determine whether a person is teenager or person's height is between 160cm to 180cm
The program should do the following:
1.
Question
Assign values for age and height variable.
2.
Check if the age is between 12 to 18 or height is between 160 to 180
3.
If both conditions are satisfied , the program should print "Yes!"
4.
If both conditions are dissatisfied, the program should print "No!"
Save the file as "XX_YYYY_03.py"
If And/Or statement - 03
Same
Differrent
1.
2.
Question
Save the file as "XX_YYYY_03.py"
Write a Python program to determine whether a person is teenager or person's height is between 160cm to 180cm
OR
age
height
Introduction to Python - if and or statement
By Mr Peter
Introduction to Python - if and or statement
- 215