wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python-loops, branches, functions

Total questions: 15

Worksheet time: 1hrs 15mins

Name
Class
Date
1.

What does this code print?

a)

A

B

C

b)

A

C

c)

A

d)

A

B

2.

What does this code print?

a)

A

B

C

b)

A

c)

A

C

d)

B

C

3.

What does the code print?

a)

B

C

b)

A

C

c)

B

d)

A

e)

C

4.

What does the code print?

a)

True True

b)

True False

c)

False True

d)

False False

5.

What does the code print?

a)

True True

b)

True False

c)

False True

d)

False False

6.

What does the code print?

a)

10

7

4

1

Done

b)

10

9

8

7

6

5

4

3

2

1

Done

c)

Done

d)

10

7

4

1

-2

-5

... and more, running infinitely.

7.

What does the code print?

a)

10 stars, then the word "Done"

b)

4 stars, then the word "Done"

c)

Just the word "Done"

d)

Infinitely many stars

8.

What does the code print?

a)

10 stars, then the word "Done"

b)

4 stars, then the word "Done"

c)

Just the word "Done"

d)

Infinitely many stars

9.

Which line of code would correctly call the function?

a)

power(base, exp)

b)

power(x, y)

c)

ans = power(base, exp)

d)

ans = power(x, y)

10.

Which line of code would correctly call the function?

a)

power(base, exp)

b)

power(x, y)

c)

ans = power(base, exp)

d)

ans = power(x, y)

11.

What gets printed?

a)

3

4 6

b)

3

3 6

c)

5

4 5

d)

5

4 6

12.

What is the value of fun(10)?

a)

1

b)

11

c)

0

d)

-1

13.

What is the value of fun(-13)?

a)

1

b)

-12

c)

0

d)

-1

14.

My code doesn't work. It should calculate 1 + 2 + 3 + 4 and print 10, but print it just prints 0.

How do I fix it?

a)

You should print sum rather than total.

b)

You need to add 1 to total inside the loop.

c)

Delete the num += 1 line.

d)

Get rid of the sum variable and just use total.

15.

The body of the while loop is hidden from you.

Which of the following is a possible values that might be printed by the last line?

a)

-8

b)

1

c)

0

d)

8