NEW
Font size
Worksheetsgrade 7&8 week 8
Total questions: 48
Worksheet time: 24mins
Which is the correct way to assign the value 10 to a variable?
10 = x
x = 10
int x = 10
set x to 10
Which function is used to get user input in Python?
input()
get()
read()
scan()
What type of data is returned by input() by default?
Integer
String
Boolean
Float
Which function is used to display output?
print()
echo()
show()
write()
Which command converts a string input into an integer?
toInt()
convert(input())
int(input())
str(input())
What is the output of this code? for i in range(3): print("Hi")
Hi (once)
Hi (3 times)
Hi (infinite)
Error
In for i in range(5):, what values does i take?
1 to 5
0 to 5
0 to 4
1 to 4
Which keyword is used in a for loop?
repeat
for
loop
do
What does this code print? for i in range(1, 4): print(i)
1 2 3
0 1 2
1 2 3 4
0 1 2 3
What does the third value in range(start, stop, step) represent?
Starting point
Ending point
Step size
Loop variable
What is a while loop used for?
Repeat for a fixed number of times
Repeat until a condition becomes false
Repeat forever
Repeat randomly
Which of these is correct syntax?
while x = 5:
while x == 5:
while (x equal 5):
while x => 5:
What is the output of this code? count = 0 while count < 3: print(count) count += 1
0 1 2
1 2 3
0 1 2 3
Infinite loop
What happens if you forget count += 1 inside a while loop?
The loop runs only once
The loop never runs
The loop becomes infinite
The loop ends automatically
Which keyword is used to exit a loop immediately?
end
stop
break
quit
Which keyword skips the current loop iteration and continues with the next?
pass
continue
break
stop
What will this code print? for i in range(5): if i == 3: break print(i)
0 1 2
0 1 2 3 4
0 1 2 3
Error
What will this code print? for i in range(5): if i == 3: continue print(i)
0 1 2 3 4
0 1 2 4
0 1 2
1 2 3 4
What does the pass statement do in a loop?
Ends the loop
Skips the iteration
Does nothing (placeholder)
Restarts the loop
Which statement is correct about for and while loops?
for is used for unknown repetitions
while is used for fixed repetitions
for is used for known repetitions
They are identical
What is the output? for i in range(3): if i % 2 == 0: print("Even")
Even (once)
Even (twice)
Even (three times)
Error
Which symbol means "equal to" in conditions?
=
==
!=
<
Which operator means "not equal"?
!
!=
==
<>
What is the output? x = 5 if x > 3: print("Yes") else: print("No")
No
Yes
5
Error
Which operator checks if a number is greater than or equal to another?
>=
>
==
<=
What does this code print? for i in range(2): for j in range(2): print(i, j)
0 0, 0 1, 1 0, 1 1
0 1, 1 2
2 2
Error
Which loop is inside another loop?
Infinite loop
Nested loop
Recursive loop
Parallel loop
Why are nested loops useful?
To run code faster
To handle multiple dimensions
To end a program
To stop cond
Which loop is better when the number of repetitions is known?
while
for
repeat
case
Which loop is better when repetitions depend on a condition?
for
while
case
if
What is the default starting number in range(5)?
0
1
5
None
What will this print? for i in range(2, 10, 3): print(i)
2 3 4 5 6 7 8 9
2 5 8
2 6 9
2 4 6 8
Which statement is correct?
for and while loops cannot be used with conditions
Loops can only run 10 times
Loops help to repeat code automatically
Loops are not used in real programs
What is the output? for i in range(4): print("Loop")
Loop (once)
Loop (three times)
Loop (four times)
Error
What is the output? i = 0 while i < 2: print("Hello") i += 1
Hello (once)
Hello (twice)
Hello (three times)
Infinite loop
What will this loop print? for i in range(1, 6): print("*" * i)
* * * * *
* ** *** **** *****
*****
Error
What does % operator mean in loops?
Division
Modulus (remainder)
Multiplication
Power
What is the role of indentation in Python loops?
Decoration only
Tells Python which code is inside the loop
To create comments
To name variables
What is the output? for i in range(3): for j in range(3): if i == j: print(i, j)
(0,0), (1,1), (2,2)
(0,1), (1,2), (2,3)
(0,2), (2,0)
Error
What is the output? x = 4 while x > 0: x -= 1 print(x)
4 3 2 1
3 2 1 0
4 3 2
Infinite
Which statement is true?
for loops always run at least once
while loops may never run
for loops are faster than while
Both loops always infinite
Which loop can create infinite loops more easily?
for
while
repeat
case
Which is an advantage of loops?
They make code shorter and reusable
They make code slower
They remove conditions
They delete variables
What is the output? for i in range(2): for j in range(3): print("*")
2 stars
3 stars
6 stars
Infinite
Which symbol means "less than"?
>
<
<=
>=
Which statement is true about range(1, 5)?
Starts at 1, ends at 5
Starts at 1, ends at 4
Starts at 0, ends at 5
Starts at 0, ends at 4
What is the output? for i in range(1, 3): print("Yes") else: print("Done")
Yes Yes
Yes Yes Done
Done only
Error
Which is the best definition of a loop?
A tool to run code repeatedly
A tool to delete variables
A way to close a program
A tool to store input
