04 Relational Operators: True or False
04 Relational Operators: True or False
46)
Relational operators compare the values on both sides and evaluate the condition
(i.e. whether it is True or False).
1. Assume that the value of variable num is 30. Fill in the logical result (True or
False) for the following expressions.
Expression Logical result
2. Assume that the value of variable score is 50. Fill in the logical result (True or
False) for the following expressions.
Expression Logical result
P. 1
3. Read the following Python program:
name = "Chris Wong"
age = 29
member = True
point = 540.5
Write down the output shown in the output cell after executing the following
codes.
Expression Logical result
P. 2
05 Conditional Statements (P. 48)
3. Read the following Python programs and write down the output shown in the
output cell.
Python code Output
X = 100
if X != 20:
(a) print("Oh") Oh
else:
print("Bingo")
tag = "car"
if tag == "car":
print("Great")
(b) Great
else:
print("Good")
print("Welcome")
point = 380
if point >= 500:
print("Welcome")
(c) Thank you
print("VIP")
else:
print("Thank you")
P. 3
4. Read the following Python programs and write down the output shown in the
output cell.
Python code Output
P = 50
if P > 100:
P = P - 10
(a) 60
if P < 80:
P = P + 10
print(P)
A = 20
B = 30
if A > B:
(b) B = B + 10 30, 30
if B > A:
A = A + 10
print(A, B)
X = 500
Y = 300
if X - Y > 100:
Y = Y + 100
(c) 400
if X + Y > 1000:
print(X)
else:
print(Y)
P. 4
Python code Output
num = 30
star = 2
if num == 30:
star = star + 5
else: Work hard
(d)
star = star - 1
if star > 10:
print("Well done")
else:
print("Work hard")
P. 5
06 Nested Conditional Statements (P. 58)
5. Read the following Python program:
if S < 100:
print("A")
elif S < 200:
print("B")
elif S < 300:
print("C")
else:
print("D")
Depending on the value of variable S, write down the output shown in the output
cell.
Value of variable S Output
(a) 550 D
(b) 100 B
(c) 150 B
(d) 50 A
P. 6
6. Read the following Python programs and write down the output shown in the
output cell.
Python code Output
B = 100
if B > 50:
(a) if B < 30: Cat
print("Dog")
print("Cat")
age = 10
if age < 18:
if age > 11:
print("Youth")
(b) Kid
else:
print("Kid")
else:
print("Adult")
X = 30
if X > 100:
print("1")
else:
if X > 50:
(c) print("2") 3
else:
if X > 25:
print("3")
else:
print("4")
P. 7
Python code Output
level = 29
power = 5
if level > 10:
if power > 3:
Level++
(d) print("Level++")
Done
else:
if power > 10:
print("Power++")
print("Done")
P. 8
07 Logic Errors (P. 59)(Advanced)
Logic errors cause the program to function abnormally or produce wrong results. If
the result outputted by the program is different from the expected result, the
program may have logic errors.
1. May is designing a Python program to determine a student’s grade according to
the obtained mark. Read the following program:
if mark >= 50:
print("C")
elif mark >= 75:
print("B")
elif mark >= 90:
print("A")
else:
print("F")
(a) The following are the expected results. Write down the actual result depending
on the value of variable mark.
Value of variable
Expected result Actual Output
mark
95 A A
80 B B
65 C C
30 F F
P. 9
2. Candice is writing a Python program to check whether the value of variable num is
within the range of 1 to 10. Read the following program:
if num >= 1:
print("Correct input")
elif num <= 10:
print("Correct input")
else:
print("Wrong input")
(a) The following are the expected results. Write down the actual result
depending on the value of variable num.
Value of variable num Expected result Actual Output
P. 10
P. 11