WorksheetsPython-loops, branches, functions
Total questions: 15
Worksheet time: 1hrs 15mins
What does this code print?
A
B
C
A
C
A
A
B
What does this code print?
A
B
C
A
A
C
B
C
What does the code print?
B
C
A
C
B
A
C
What does the code print?
True True
True False
False True
False False
What does the code print?
True True
True False
False True
False False
What does the code print?
10
7
4
1
Done
10
9
8
7
6
5
4
3
2
1
Done
Done
10
7
4
1
-2
-5
... and more, running infinitely.
What does the code print?
10 stars, then the word "Done"
4 stars, then the word "Done"
Just the word "Done"
Infinitely many stars
What does the code print?
10 stars, then the word "Done"
4 stars, then the word "Done"
Just the word "Done"
Infinitely many stars
Which line of code would correctly call the function?
power(base, exp)
power(x, y)
ans = power(base, exp)
ans = power(x, y)
Which line of code would correctly call the function?
power(base, exp)
power(x, y)
ans = power(base, exp)
ans = power(x, y)
What gets printed?
3
4 6
3
3 6
5
4 5
5
4 6
What is the value of fun(10)?
1
11
0
-1
What is the value of fun(-13)?
1
-12
0
-1
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?
You should print sum rather than total.
You need to add 1 to total inside the loop.
Delete the num += 1 line.
Get rid of the sum variable and just use total.
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?
-8
1
0
8
