Midterm computer
What would 10 % 3 calculate to?
1
What values of i are produced from the following line of code? for i in range(2, 10, 2): 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 2, 4, 6, 8, 10 2, 4, 6, 8 2, 3, 4, 5, 6, 7, 8
2, 4, 6, 8
Answer the following questions about the program below. 1 penup() 2 backward(150) 3 right(90) 4 forward(50) 5 left(90) 6 color("gold") 7 for i in range(4): 8 pendown() 9 circle(50) 10 penup() 11 forward(100) a. Draw the output of this turtle program below. (Ignore color command)
4 circles horizontally across
How many circles will Tracy draw when the following program is run? for i in range(4): circle(10) forward(10) circle(20) forward(20) 4 circles 8 circles 10 circles 40 circles
8 circles
a. What control structure did you use in your program rewrite? for(I) in range(4): forawrd(100) right(90)
A for loop
Answer the following questions about the program below. 1 forward(100) 2 left(90) 3 backward(100) 4 right(90) 5 backward(100) 6 left(90) 7 forward(100) a. What does this Turtle Graphics program draw?
A square
Which of the following names should pet_name be assigned to make this program print "I think your pet is named fluffy!"?
Spot
What is the most efficient way to shorten the following code? def draw_small_square(): for i in range(4): forward(50) left(90) def draw_big_square(): for i in range(4): forward(100) left(90) draw_small_square() draw_big_square()
Use a parameter value
a. Rewrite this program to allow the user to determine the color of the circles. 1 penup() 2 backward(150) 3 right(90) 4 forward(50) 5 left(90) 6 color("gold") 7 for i in range(4): 8 pendown() 9 circle(50) 10 penup() 11 forward(100)
add circle_color = input("Choose color: ") color(circle_color)
What would you use if you wanted to ask the user for the number of ounces of water he/she drank that day, and then print one of two messages based on the number? if while for if/Else
if/else
Which line in the following code contains an error? 1 secret_number = 5 2 3 user_number = int(input("Guess a number: ")) 4 5 if secret_number = user_number: 6 print("Great work!") 7 else: 8 print("That's not it.")
line 5
Answer the following questions about the program below. 1 speed = int(input("What is your speed? ")) 2 if speed > 80: 3 print ("You will get a reckless driving charge.") 4 elif speed > 60: 5 print ("You will get a speeding ticket.") 6 else: 7 print ("You are driving at a safe speed.") What does this program do?
A user enters a speed value and this program tells them if they will get a reckless driving charge, a speeding ticket, or if they are driving at a safe speed.
Which of the following python lines contains a valid comment
Def get_name(): # get the user's name
Tracy's starting location is in the top left hand corner at coordinate (0,0).
False; (0,0) is located at the center of the canvas
The expression 4 < 4 will evaluate to ... ?
False; 4 is not less than 4.
A boolean has the value of True, False, or None.
False; a boolean only has the value of True or False.
In the following function snippet, the name of the function is circle_color. def draw_circle(circle_color):
False; circle_color is a parameter. draw_circle is the function name.
A variable can be any type.
True
The input function returns a string.
True
The keyword int must be used to use a string as a number in mathematical expressions.
True
To compare two floats, you should call the round function on each number.
True
To print a string and a number variable using the same print statement, the number must be given to the str function first.
True
and, or, not are all examples of logical operators.
True
What is the type of a variable with a value of 5.4? float integer string boolean
float
a. Rewrite this program to draw the same image in a more efficient way using only 3 lines of code. (Don't forget about where the image is being placed!) 1 forward(100) 2 left(90) 3 backward(100) 4 right(90) 5 backward(100) 6 left(90) 7 forward(100)
for(I) in range(4): forawrd(100) right(90)
Which of the following print statements correctly combines a string variable name and an integer variable age to print out a sentence such as "Charlie is 13 years old"? print(int(name) + " is" + age + " years old") print(name + " is " + age + " years old") print(name + " is " + int(str(age)) + " years old") print(name + " is " + str(age) + " years old")
print(name + " is " + str(age) + " years old")