wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

grade 7&8 week 8

Total questions: 48

Worksheet time: 24mins

Name
Class
Date
1.

Which is the correct way to assign the value 10 to a variable?

a)

10 = x

b)

x = 10

c)

int x = 10

d)

set x to 10

2.

Which function is used to get user input in Python?

a)

input()

b)

get()

c)

read()

d)

scan()

3.

What type of data is returned by input() by default?

a)

Integer

b)

String

c)

Boolean

d)

Float

4.

Which function is used to display output?

a)

print()

b)

echo()

c)

show()

d)

write()

5.

Which command converts a string input into an integer?

a)

toInt()

b)

convert(input())

c)

int(input())

d)

str(input())

6.

What is the output of this code? for i in range(3): print("Hi")

a)

Hi (once)

b)

Hi (3 times)

c)

Hi (infinite)

d)

Error

7.

In for i in range(5):, what values does i take?

a)

1 to 5

b)

0 to 5

c)

0 to 4

d)

1 to 4

8.

Which keyword is used in a for loop?

a)

repeat

b)

for

c)

loop

d)

do

9.

What does this code print? for i in range(1, 4): print(i)

a)

1 2 3

b)

0 1 2

c)

1 2 3 4

d)

0 1 2 3

10.

What does the third value in range(start, stop, step) represent?

a)

Starting point

b)

Ending point

c)

Step size

d)

Loop variable

11.

What is a while loop used for?

a)

Repeat for a fixed number of times

b)

Repeat until a condition becomes false

c)

Repeat forever

d)

Repeat randomly

12.

Which of these is correct syntax?

a)

while x = 5:

b)

while x == 5:

c)

while (x equal 5):

d)

while x => 5:

13.

What is the output of this code? count = 0 while count < 3: print(count) count += 1

a)

0 1 2

b)

1 2 3

c)

0 1 2 3

d)

Infinite loop

14.

What happens if you forget count += 1 inside a while loop?

a)

The loop runs only once

b)

The loop never runs

c)

The loop becomes infinite

d)

The loop ends automatically

15.

Which keyword is used to exit a loop immediately?

a)

end

b)

stop

c)

break

d)

quit

16.

Which keyword skips the current loop iteration and continues with the next?

a)

pass

b)

continue

c)

break

d)

stop

17.

What will this code print? for i in range(5): if i == 3: break print(i)

a)

0 1 2

b)

0 1 2 3 4

c)

0 1 2 3

d)

Error

18.

What will this code print? for i in range(5): if i == 3: continue print(i)

a)

0 1 2 3 4

b)

0 1 2 4

c)

0 1 2

d)

1 2 3 4

19.

What does the pass statement do in a loop?

a)

Ends the loop

b)

Skips the iteration

c)

Does nothing (placeholder)

d)

Restarts the loop

20.

Which statement is correct about for and while loops?

a)

for is used for unknown repetitions

b)

while is used for fixed repetitions

c)

for is used for known repetitions

d)

They are identical

21.

What is the output? for i in range(3): if i % 2 == 0: print("Even")

a)

Even (once)

b)

Even (twice)

c)

Even (three times)

d)

Error

22.

Which symbol means "equal to" in conditions?

a)

=

b)

==

c)

!=

d)

<

23.

Which operator means "not equal"?

a)

!

b)

!=

c)

==

d)

<>

24.

What is the output? x = 5 if x > 3: print("Yes") else: print("No")

a)

No

b)

Yes

c)

5

d)

Error

25.

Which operator checks if a number is greater than or equal to another?

a)

>=

b)

>

c)

==

d)

<=

26.

What does this code print? for i in range(2): for j in range(2): print(i, j)

a)

0 0, 0 1, 1 0, 1 1

b)

0 1, 1 2

c)

2 2

d)

Error

27.

Which loop is inside another loop?

a)

Infinite loop

b)

Nested loop

c)

Recursive loop

d)

Parallel loop

28.

Why are nested loops useful?

a)

To run code faster

b)

To handle multiple dimensions

c)

To end a program

d)

To stop cond

29.

Which loop is better when the number of repetitions is known?

a)

while

b)

for

c)

repeat

d)

case

30.

Which loop is better when repetitions depend on a condition?

a)

for

b)

while

c)

case

d)

if

31.

What is the default starting number in range(5)?

a)

0

b)

1

c)

5

d)

None

32.

What will this print? for i in range(2, 10, 3): print(i)

a)

2 3 4 5 6 7 8 9

b)

2 5 8

c)

2 6 9

d)

2 4 6 8

33.

Which statement is correct?

a)

for and while loops cannot be used with conditions

b)

Loops can only run 10 times

c)

Loops help to repeat code automatically

d)

Loops are not used in real programs

34.

What is the output? for i in range(4): print("Loop")

a)

Loop (once)

b)

Loop (three times)

c)

Loop (four times)

d)

Error

35.

What is the output? i = 0 while i < 2: print("Hello") i += 1

a)

Hello (once)

b)

Hello (twice)

c)

Hello (three times)

d)

Infinite loop

36.

What will this loop print? for i in range(1, 6): print("*" * i)

a)

* * * * *

b)

* ** *** **** *****

c)

*****

d)

Error

37.

What does % operator mean in loops?

a)

Division

b)

Modulus (remainder)

c)

Multiplication

d)

Power

38.

What is the role of indentation in Python loops?

a)

Decoration only

b)

Tells Python which code is inside the loop

c)

To create comments

d)

To name variables

39.

What is the output? for i in range(3): for j in range(3): if i == j: print(i, j)

a)

(0,0), (1,1), (2,2)

b)

(0,1), (1,2), (2,3)

c)

(0,2), (2,0)

d)

Error

40.

What is the output? x = 4 while x > 0: x -= 1 print(x)

a)

4 3 2 1

b)

3 2 1 0

c)

4 3 2

d)

Infinite

41.

Which statement is true?

a)

for loops always run at least once

b)

while loops may never run

c)

for loops are faster than while

d)

Both loops always infinite

42.

Which loop can create infinite loops more easily?

a)

for

b)

while

c)

repeat

d)

case

43.

Which is an advantage of loops?

a)

They make code shorter and reusable

b)

They make code slower

c)

They remove conditions

d)

They delete variables

44.

What is the output? for i in range(2): for j in range(3): print("*")

a)

2 stars

b)

3 stars

c)

6 stars

d)

Infinite

45.

Which symbol means "less than"?

a)

>

b)

<

c)

<=

d)

>=

46.

Which statement is true about range(1, 5)?

a)

Starts at 1, ends at 5

b)

Starts at 1, ends at 4

c)

Starts at 0, ends at 5

d)

Starts at 0, ends at 4

47.

What is the output? for i in range(1, 3): print("Yes") else: print("Done")

a)

Yes Yes

b)

Yes Yes Done

c)

Done only

d)

Error

48.

Which is the best definition of a loop?

a)

A tool to run code repeatedly

b)

A tool to delete variables

c)

A way to close a program

d)

A tool to store input