WorksheetsQuiz 2 - ComProg1 - MakScie
Total questions: 50
Worksheet time: 50mins
What is the output of 7 // 3 in Python?
2.33
2
3
2.0
Which operator has the highest precedence in Python?
*
+
**
%
What is the result of 15 % 4?
3
4
1
2
Which of the following will return True?
5 == '5'
5 is 5.0
5 != 6
'a' > 'z'
Which of these operators is used for exponentiation in Python?
^
**
^^
exp
What is the result of 2 ** 3 ** 2?
64
512
256
8
Which of the following evaluates to False?
not (5 > 3)
(4 < 10) and (10 > 2)
(6 == 6) or (7 < 2)
5 <= 5
What will 10 / 3 return in Python 3?
3
3.0
3.33…
Error
What is the output of 9 & 12 (bitwise AND)?
12
8
9
0
Which operator is used for floor division?
/
//
%
div
What is the output of True + False?
0
1
2
Error
What is the result of ~5 (bitwise NOT)?
5
-5
-6
6
Which of the following is NOT a valid logical operator?
and
or
xor
not
If a = 7, which expression evaluates to True?
a % 2 == 0
a // 3 == 2
a ** 2 < 40
a < 5
What does a += 5 mean?
a = a + 5
a = a - 5
a = 5
a = a * 5
What is the type of the result of 7 / 2?
int
float
decimal
complex
Which operator is used for identity comparison?
==
is
in
===
What is the output of '5' * 3?
15
555
Error
'53'
Which expression evaluates to True?
'apple' < 'banana'
'Zebra' > 'apple'
'abc' == 'ABC'
len('hi') > 5
What does 10 >> 1 return?
5
20
2
8
What is the output? x = 10 if x > 5: print("A") else: print("B")
A
B
AB
Error
Which keyword is used to end an if block?
endif
break
else
Indentation
What will this print? if False: print("Yes") else: print("No")
Yes
No
Error
Nothing
What is printed? x = 0 if x: print("True") else: print("False")
True
False
Error
None
Which values are treated as False in if conditions?
0
[]
None
All of the above
Identify the correct syntax.
if (x > 5)
if x > 5:
if x > 5 {
if x > 5 then
What is printed? x = 5 if x == 5: print("Equal") else: print("Not equal")
Equal
Not equal
Error
None
What happens if if condition is not indented?
Executes normally
SyntaxError
Prints nothing
Ignores indentation
What is printed? if 'a' in 'cat': print("Yes") else: print("No")
Yes
No
Error
None
What is the output? if 1: print("One") else: print("Zero")
One
Zero
Error
Nothing
In Python, if statements can be combined using:
and/or
with/without
do/while
switch/case
What is printed? x = 10 if x < 5: print("Small") else: print("Large")
Small
Large
Error
Nothing
Which of the following is invalid?
if x:
if not x:
if (x > y):
if x then:
Which statement is correct?
if can exist without else.
else can exist without if.
elif can exist without if.
if requires else.
What is printed? if []: print("List") else: print("Empty")
List
Empty
Error
None
What is printed? x = 3 if x > 5: print("A") elif x == 3: print("B") else: print("C")
A
B
C
None
Which statement is correct about elif?
Can appear before if
Must follow if
Must follow else
Optional in Python
What is printed? x = 8 if x < 5: print("Low") elif x < 10: print("Medium") else: print("High")
Low
Medium
High
Error
Which of these is valid?
if…elif…else
if…else if…else
if…elseif…end
if…elif…end
What is printed? x = 10 if x > 15: print("A") elif x > 5: print("B") else: print("C")
A
B
C
None
How many elif blocks can Python support?
Only 1
2
Unlimited
None
Which is correct nesting?
if…elif…elif…else
if…elif…else if…else
if…elseif…else
if…if…else only
What is printed? x = 0 if x < 0: print("Negative") elif x == 0: print("Zero") else: print("Positive")
Negative
Zero
Positive
None
What is the output? x = 15 if x < 10: print("A") elif x < 20: print("B") elif x < 30: print("C") else: print("D")
A
B
C
D
What is printed? x = 25 if x < 10: print("Small") elif x < 20: print("Medium") else: print("Large")
Small
Medium
Large
Error
Which statement is incorrect?
Only the first matching if/elif executes.
elif prevents multiple matches.
All elif conditions are always checked.
else is optional.
What will be the output? x = 7 if x % 2 == 0: print("Even") elif x % 2 != 0: print("Odd") else: print("None")
Even
Odd
None
Error
What is printed? score = 85 if score >= 90: print("A") elif score >= 80: print("B") else: print("C")
A
B
C
Error
Which of the following is valid?
if x: elif y: else:
if x: else: elif y:
if x: elif y:
if x: pass elif y:
What is printed? x = 12 if x % 3 == 0: print("Divisible by 3") elif x % 4 == 0: print("Divisible by 4") else: print("Other")
Divisible by 3
Divisible by 4
Other
None
