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
And/Or Condition
Same
Differrent
1.
2.
if Condition1
And condition: All conditions need to be True
Command
True
True
and
Condition2:
And/Or Condition
Same
Differrent
1.
2.
if Condition1
Or condition: Either one of the condition is True
Command
True
False
or
Condition2:
If And/Or statement - Ex07_1
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_Ex07_1.py"
If And/Or statement - Ex07_1
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_Ex07_1.py"
If And/Or statement - Ex07_2
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_Ex07_2.py"
If And/Or statement - Ex07_2
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_Ex07_2.py"
If And/Or statement - Ex07_3
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_Ex07_3.py"
If And/Or statement - Ex07_3
Same
Differrent
1.
2.
Question
Save the file as "XX_YYYY_Ex07_3.py"
Write a Python program to determine whether a person is teenager or person's height is between 160cm to 180cm
OR
age
height