WorksheetsPython Review 2023-01-12
Total questions: 10
Worksheet time: 12mins
What does this function do?
Returns the product of its parameters
Returns the sum of its parameters
Returns the largest of its parameters
Returns the smallest of its parameters
What will this code snippet print?
cow
sheep
pig
ox
You want to write code to aske the user to enter his or her favorite food and then print "good" if the response is "fries" and "bad" if it isn't. Reorder the statements below to accomplish this.
How would you write a for loop to repeat 15 times using a counter variable called count?
for (a) (b) (c) (d)
You want to create a conditional to check whether a variable called n is positive. How would you do this?
(a) n (b) (c) (d)
A (a) loop repeats a specified number of times. A (b) loop repeats as long as a condition is met.
Match each description with the code snippet that is an example of that description.
conditional
function
for loop
while loop
list
A (a) is a data structure that stores multiple pieces of data in a single variable. The values in a list are called (b) and you can reference specific elements in a list by using a(n) (c) which is an integer that specifies the position of the data in the list and which starts counting at (d) .
Given this code snippet, match the following python expressions with their values.
-2
stuff[3]
0
stuff[2]
4
stuff[7]
-6
stuff[6]
13
stuff[1]
What values for a and b will cause this code snippet to print "aardvark"?
a = 12, b = 4
a = 13, b = 3
a = 34, b = -6
a = 20, b = 0
