O Level Computer Science – Python Programming
Worksheet
Topic: Selection (IF Statements)
Name: ____________________ Class: ____________________ Date: ____________________
Learning Objectives
• Use if statements in Python
• Use if...else statements
• Use if...elif...else statements
• Apply comparison operators
• Write simple decision-making programs
Part A – Multiple Choice Questions
1. Which keyword is used for selection in Python?
A. repeat B. if C. loop D. select
2. What will this code display?
age = 18
if age >= 18:
print("Adult")
A. Child B. Teenager C. Adult D. Error
3. Which operator means “not equal to”?
A. == B. >= C. != D. =
4. What is the output?
x = 5
if x > 10:
print("Big")
else:
print("Small")
A. Big B. Small C. 5 D. Error
Part B – Fill in the Blanks
1. The keyword used for an alternative condition is __________.
greater than or equal
2. The symbol >= means __________________. to
3. A condition that is either True or False is called a ____________.
else id
4. The keyword elif means __________________.
python code
5. Indentation is important in __________________.
Part C – Trace the Code
Question 1
temperature = 30
if temperature > 25:
print("Hot")
else:
print("Cold")
Hot
Output: _______________________
Question 2
marks = 45
if marks >= 50:
print("Pass")
else:
print("Fail")
Fail
Output: _______________________
Part D – Programming Exercises
1. n=int(input("enter a number"))
1. Even or Odd if n / 2 :
print("even")
Write a program that inputs a number and displays whether it is Even or Odd. else :
print("odd")
_________________________________________________________
2. m=int(input("enter a marks"))
2. Pass or Fail if m>=50:
print("pass")
Write a program that inputs marks and displays Pass or Fail. else:
print("fail")
_________________________________________________________
3. n=int(input("enter a number"))
3. Positive, Negative or Zero if n>=1:
print("positive")
Write a program to check whether a number is positive, negative or zero.
elif n==0:
print("zero")
else:
_________________________________________________________ print("negative")
Part E – Challenge Question
Write a program that asks the user to enter a username and password.
• If username is "admin" and password is "1234", display "Login Successful"
• Otherwise display "Invalid Login" u = input("Enter username: ")
p = int(input("Enter password: "))
_________________________________________________________ if u == "admin":
if p == 1234:
print("Login Successful")
_________________________________________________________ else:
print("Invalid Login")
Teacher Notes – Comparison Operators
| Operator | Meaning |
| == | Equal to |
| != | Not equal to |
| > | Greater than |
| < | Less than |
| >= | Greater than or equal to |
| <= | Less than or equal to |