11.1.1 Final Exam Pt 1: Multiple Choice
What function would you use to get the position of a character in a string?
find
Given the following 2D list, which of the following expressions would get the element "cucumber"? food = [ ["apple", "banana", "kumquat"] ["cucumber", "onion", "squash"] ["candy", "soda", "sugar"] ]
foods[1][0]
What is the type of the variable x? x = 5
int
Consider the following code: total = 0 for i in range(5): total += i print total What is the result of running this program code?
10
What is the total forward distance moved when the code below is run? def moveForward(): for i in range (2): forward(50) moveForward() moveForward()
200
What would be printed to the screen when the following program is run? def returnNumber(x): return x + 3 print returnNumber(2)
5
What will the value of sum be after the following code runs? sum = 0 for i in range (0, 6, 2): for j in range (2): sum = sum + 1
6
How many times would the phrase 'codeHS' be printed in the following scenario: repeat 2 times repeat 4 times print "codeHS"
8 times
Evaluate the mathematical expression: 10 - 6 x (4 - 2) / 2 + 5.
9
What is the difference between a for loop and a while loop?
A for loop repeats commands a specific number of times and a while loop repeats until a condition becomes false.
What is wrong with the following function? def compute_total_pay(hourley_rate=10.5, overtime_rate=15, num_hours): if num_hours <= 40: return hourly_rate * num_hours return 40*hourly_rate + (num_hours - 40) * overtime_rate
Any parameters that don't have default values must come before any parameters that do have default values
Which of the following describes a task effectively broken into smaller parts? I. Writing a book by brainstorming, making an outline, and drafting the first chapter II. Comparing two different cameras III. Using your phone's calculator
I only
Eliza will wear a coat if it is raining or if it is less than 50° F outside. Otherwise, Eliza will leave her coat at home. In which of the following cases will Eliza leave her coat at home?
It is not raining and 50°F
What would be the output of the following code? text = "hello" if "a" in text: print "Yes" elif "ll" in text: print "Maybe" else: print "No"
Maybe
Tracy the Turtle is given the following instructions: repeat 2 times: forward 100 units turn left 120 degrees f orward 100 units turn left 60 degrees Given Tracy's starting point below, what will be the result of running this program code?
The one with the complete rhombus (not the square), it has 4 sides and is slanted. I believe its the last one
What would be the output of the following code? for i in range(2): print "Tracy" print "Turtle'
Tracy Tracy Turtle
What would the output of the following code be? x = "Tracy" print x*5
TracyTracyTracyTracyTracy
The following snippet is from a program that asks the user what he/she wants to order. The user's input is stored in the variable item_ordered. If the user enters 3, what will the following code snippet print? item_ordered = input("Enter the name of the item you wish to order: ") try: print "You have ordered the following item: " + item_ordered except TypeError: print "I'm sorry. You have entered an invalid item."
You have ordered the following item: 3
What would be the output of the following code? colors = ["red", "green", "blue", "yellow"] color.reverse() colors.append("orange") colors.sort() print colors
["blue", "green", "orange", "red", "yellow"]
What is the value of the list after this program runs? days = ['Mon', 'Tues', 'Wed', 'Thurs', 'Fri'] days.reverse() days.extend(['Sat', 'Sun'])
['Fri', 'Thurs', 'Wed', 'Tues', 'Mon', 'Sat', 'Sun']
What list is produced using the following list comprehension? word = "butterfly" [w for w in word]
['b', 'u', 't', 't', 'e', 'r', 'f', 'l', 'y']
What is the result of word[-3] if word = "chalkboard"?
a
Which of the following boolean expressions would make the while loop find the first animal in the list whose length is longer than 8? animals = ['snowy owl', 'salamander', 'bunny', 'octopus', 'squirrel', 'buffalo'] cur = 0 while ____________: cur +=1 print "First animal with length longer than 8 is " + animals[cur]
len(animals[cur]) <= 8
Which of the following operations will cause an error?
ribbon_colors = ("blue", "red", "green") ribbon_colors[2] = "silver"
If x represents the area of the number line colored blue, which inequality accurately reflects the value of x?
x ≤ 5