WorksheetsPart 1 Final Tech Exam
Total questions: 60
Worksheet time: 15hrs 0mins
When the following for loop is complete, how many spaces will Tracy have moved?
for i in range(5):
forward(10)
50 spaces
60 spaces
10 spaces
5 spaces
Suppose you write a function. How many times can you call the function in your code?
Once
Not more than the number of commands the function holds
It depends on the function
As many times as you want
In which of the following situations would it be best to make a function?
You want Tracy to draw a blue line, and your program requires lots of blue lines.
You need Tracy to move forward by 100.
You need Tracy to turn right and then turn left.
You need to change Tracy’s color.
Which of the following pieces of code will make Tracy do the following actions three times: go forward, change colors, and then turn around.
for i in range(4):
forward(30)
color("blue")
left(180)
for i in range(3):
forward(30)
color("blue")
left(180)
color("red")
for i in range(3):
backward(30)
color("blue")
left(180)
forward(30)
color("blue")
left(180)
forward(30)
color("green")
left(180)
forward(30)
color("orange")
left(180)
Suppose you want to make Tracy draw a mountain range, like the one shown below, starting from the left side.
Which of the following functions would be the most useful function to write in order to solve this problem?
# Has Tracy draw a single triangle
def make_triangle():
# Change's Tracy's color to red
def change_to_red()
# Moves Tracy forward by 100
def move_100():
# Draws a square
def my_function():
Which of the following is NOT a command you can give to Tracy?
color
turn
backward
left
Which of the statements below is true about indentation in Python?
Indentation only matters in for loops. Then, everything must be indented one level.
Indentation never matters in Python. You can align your code any way you like, but indentation makes your code easier to read.
Indentation always matters in Python. Every statement must be aligned correctly.
Indentation only matters in functions. Then, everything must be indented one level.Answered Indentation only matters in functions. Then, everything must be indented one level.
Which of the following statements are true about for loops?
A. By default, the range function starts at 0
B. Using for i in range(4) will result in i taking the values 0, 1, 2, 3, 4
C. For loops let you repeat something any number of times
D. Statements in a for loop do not need to be indented
E. It is not possible to have the range values count 6, 12, 18, 24
F. It is not possible to have the range values count 1, 2, 4, 8, 16
A, C, and F
A, B, C, and F
A, B, C, E, and F
A and C
Which of the following functions is defined correctly?
def draw_edge():
forward(100)
left(90)
def draw_edge()
forward(100)
left(90)
def draw_edge
forward(100)
left(90)
def draw_edge(){
forward(100)
left(90)
}
Which of the following is NOT a purpose of using functions?
Functions let Tracy do new things.
Functions help group statements together to make your code more readable.
Functions let you execute code a fixed number of times.
Functions allow the programmer to reuse code.
What is the difference between defining and calling a function?
Defining a function means you are teaching the computer a new word. Calling a function means you are commanding the computer to complete defined actions.
There is no difference.
Calling a function means you are teaching the computer a new word. Defining a function means you are commanding the computer to complete defined actions.
Defining a function must be done each time you want to use the function. Calling a function can only happen once in your code.
What does the number in the parentheses in a forward or backward command represent?
How many degrees Tracy is supposed to turn
How fast Tracy is supposed to move
How many times Tracy should repeat the command
How far Tracy is supposed to move
What control structure would be best to use in the following code?
backward(100)
right(90)
backward(100)
right(90)
backward(100)
right(90)
backward(100)
right(90)
A function
A while loop
A for loop
An if/else statement
Which of the following commands can be used to turn Tracy to face North if she is initially facing South?
left(90)
right(90)
right(180)
right(90)
left(180)
right(90)
left(180)
Which program below includes no errors?
#
Draw a square
#
for i in range(4):
left(90)
forward(40)
# Draw a square
def draw square:
for i in range(4):
left(90)
forward(90
# Draw a square
for i in range(4):
left(90)
forward(90)
# Draw a square
def draw square():
for i in range(4):
left(90)
forward(90)
Which of the following commands can NOT be used to draw one square?
forward(50)
left(90)
forward(50)
left(90)
forward(50)
left(90)
forward(50)
left(90)
for i in range(4):
forward(50)
left(90)
circle(50, 360, 4)
for i in range(4):
circle(50, 360, 4)
What shape will be drawn with the following command?circle(50, 360, 3)
A circle
A hexagon
A triangle
A diamond
How can we use variable to control the size of a circle?
radius = 50
circle(radius)
radius = circle(50)
circle(radius)
radius = 50
radius = 50
circle(50)
Can a user’s input control the size of a circle? If so, how?
No, user input is a string.
Yes
circle(user_input=50)
Yes
radius = int(input("Radius: "))
circle(radius)
Yes
radius = input("Radius: ")
circle(radius)
What is the most effective way to draw three circles in a row of different colors?
for i in range(3):
circle(50)
penup()
forward(100)
pendown()
color("red")
def draw_circle(color_choice):
pendown()
begin_fill()
circle(50)
end_fill()
penup()
forward(50)
color("red")
draw_circle()
color("blue")
draw_circle()
color("yellow")
draw_circle()
def draw_circle(color_choice):
pendown()
color(color_choice)
begin_fill()
circle(50)
end_fill()
penup()
forward(100)
draw_circle("red")
draw_circle("blue")
draw_circle("yellow")
def draw_circle(color_choice):
pendown()
color(color_choice)
begin_fill()
circle(50)
end_fill()
penup()
forward(50)
draw_circle("red")
draw_circle("blue")
draw_circle("yellow")
What will be the output of the following program?
for i in range(3, 7, 2):
circle(50, 360, i)
Three circles with radii of 3, 7 and 2.
Three shapes- a triangle (3 sides), a heptagon (7 sides), and a line (2 sides).
Three shapes- a triangle (3 sides), a pentagon (5 sides), and a heptagon (7 sides).
Two shapes- a triangle (3 sides) and a pentagon (5 sides).
What will be the radii of the circles drawn from the following code?
for i in range(10, 55, 10):
circle(i)
10, 20, 30, 40, 50
10, 15, 20, 25, 30, 35, 40, 45, 50, 55
10, 55, 10
10, 20, 30, 40, 50, 55
Which command will Tracy perform when given the following code?
count = 200
count = count + 1
if count % 2 == 0:
forward(count)
backward(count)
forward(200)
backward(200)
forward(201)
backward(201)
Which command will Tracy perform when given the following code?
count = 5
count = count * 2
if count < 10:
forward(count)
elif count < 20:
backward(count)
else:
circle(count)
forward(10)
backward(10)
backward(10)
circle(10)
circle(10)
What will be the output of the following code?
count = 5
while count > 0:
circle(50)
forward(100
5 circles in a row
4 circles in a row
A slinky with 5 circles
An infinite loop will occur
What is the final result of the expression 4 + 5 * 3?
27
12
21
19
What is the final result of the expression 7 / 2 + 6?
0
9.5
9
0.875
Choose the print statement below that will cause an error. Assume that num has the value 6, and name has the value Isabella.
print(name + ":" )
print(num)
print(name + " wants " + "num " + "candies")
print(name + ": " + str(num))
print(name + ": " + num)
Which one of the statements below will cause an error?
ans = “hi” * 8
ans = “hi” + 9
ans = “hi” + “hi” + “hi”
ans = (“a” * 4) + “b” ans = (“a” * 4) + “b”
What does the following program print?
a = "hi"
b = 4
c = a * b
print(type(c))
<type 'str'>
<type 'int'>
<type 'float'>
The program crashes and doesn’t print anything.
The program crashes and doesn’t print anything.
str
int
float
number number
Choose the option that correctly prints out the variable(s).
x = "codehs"
print(int(x))
num = 8
print("num")
name = "Alyx"
age = 32
print(name + "is " + age)
language = "Python"
print("I'm learning " + language)
What kind of data does a float variable contain?
Whole numbers
Words
Numbers that can have decimal components
A float is not a Python variable type A float is not a Python variable type
What does the following code print?
x = 3.4
y = 1
print(int(x))
print(x + y)
3.4
4.4
3
4.4
3
4
The code causes an error
Which of the following options is the best way to get a number from the user that you plan to use in a mathematical equation?
num = str(input(“Enter a number: “))
num = number(input(“Enter a number: “))
num = input(“Enter a number: “)
num = int(input(“Enter a number: “))
What is the final result of the expression 2**3?
6
8
2
That is not a valid Python expression.
What is the character that in-line Python comments begin with?
#
%
-
"
What is the difference between a binary operator and a unary operator?
A computer can use binary operators, but it cannot use unary operators.
A unary operator needs two things, while a binary operator only needs one.
A binary operator needs two things, while a unary operator only needs one.
Binary operators are used for arithmetic expressions, while unary operators are for strings.
weight = input("How much do you weigh? ")
oz_water = weight / 2
print("You should drink " + str(oz_water))
print("ounces of water every day if you weigh " + weight)
Line 1
Line 2
Line 3
Line 4
In what order should these statements be executed in order to get input from the user and print out the result?
A) response = input("Do you like cheese? ")
B) print("You have chosen " + confirm)
C) print("You responded " + response)
D) confirm = input("Are you sure? ")
A, B, C, D
B, C, A, D
A, C, D, B
C, B, A, D
What is the output of the following program? Assume the user enters “Florence”, then “Fernandez”.
first_name = input("What is your first name? ")
last_name = input("What is your last name? ")
whole_name = first_name + last_name
print(whole_name)
Fernandez Florence
Florence
Fernandez
FlorenceFernandez
Florence Fernandez
Which of the following statements is true about print statements?
I. In order to print a string literal, the string must be enclosed in quotes.
II. Each print statement will be printed on its own line.
III. Print statements will not let you print string and number characters in the same statement.
IV. Print statements are how you display text on the screen.
I, IV
II, III
I, II, IV
I, III, IV
Which of the following choices is a properly formed Python variable name, meaning it is both legal in the Python language and considered good style?
user_age
uSeRaGe
user!age!
1user_age
Which of the following choices is NOT a Python variable type?
int
str
float
number
Choose the correct declaration of a float variable with the value 3.14.
pi = “3.14”
pi = int(3.14)
pi = 3.14
float pi = 3.14
What does this program print?
favorite_color = "blue"
if favorite_color != "blue":
if favorite_color != "red":
print("Must be yellow")
elif favorite_color == "blue":
if favorite_color != "yellow":
print("Must be blue")
elif favorite_color == "blue":
if favorite_color != "yellow":
print("I like purple")
else:
if favorite_color == "blue":
print("Blue is the best")
Must be yellow
Must be blue
I like purple
Blue is the best
Must be blue
Blue is the best
How would you round the number held in the variable pi to 3.14?
pi = 3.14159265
round(pi)
round(pi, 3)
round(3, pi)
round(pi, 2)
Why should you use round when you compare two numbers that have type float?
If you don’t, Python will only compare the whole part and discard the decimal part.
You don’t have to, but it’s good style. All of the comparisons will still work out the same way.
Sometimes numbers can be rounded in unexpected ways based on how Python computes them. Therefore, it is best to use round in order to make sure both numbers are rounded the same way.
You should always use round when you compare two numbers, even if they are of type int.
What will print to the screen when the following program is run?
number = 5
greater_than_zero = number > 0
print(type(number))
5
True
<type ‘int’>
<type ‘bool’>
What will print to the screen when the following program is run?
number = 5
less_than_zero = number < 0
print(type(less_than_zero))
5
False
<type ‘int’>
<type ‘bool’>
What will be the output of this program?
number = 5
greater_than_zero = number > 0
if greater_than_zero:
print(number)
0
5
True
Nothing will print
What will be the output of this program?
number = 5
greater_than_zero = number > 0
if greater_than_zero:
if number > 5:
print(number)
0
5
True
Nothing will print
What will be the output of this program?
number = 5
less_than_zero = number < 0
if less_than_zero:
print(number)
number = number-10
less_than_zero = number < 0
if less_than_zero:
print(number)
5
5
-5
5
-5
Nothing will print
What will be the output of this program?
number = 5
greater_than_zero = number > 0
less_than_zero = number < 0
if greater_than_zero:
print(number)
if less_than_zero:
print(number + 1)
if greater_than_zero and less_than_zero:
print(number + 2)
if greater_than_zero or less_than_zero:
print(number + 3)
5
5
7
5
7
8
5
8
What will the following program print when run?
above_16 = True
has_permit = True
passed_test = False
if above_16 and has_permit and passed_test:
print("Issue Driver's License")
elif above_16 or has_permit or passed_test:
print("Almost eligible for Driver's License")
else:
print("No requirements met.")
Issue Driver’s License
Almost eligible for Driver’s License
No requirements met
Nothing will print
What will the following program print when run?
number_one = 5
number_two = 10
if number_one == 5:
print(1)
if number_one > 5:
print(2)
if number_two < 5:
print(3)
if number_one < number_two:
print(4)
if number_one != number_two:
print(5)
1
1
3
5
1
4
1
4
5
What will the following program print when run?
number_one = 5
number_two = 10
if number_one == 5:
print(1)
elif number_one > 5:
print(2)
elif number_two < 5:
print(3)
elif number_one < number_two:
print(4)
elif number_one != number_two:
print(5)
else:
print(6)
1
1
3
5
1
4
1
4
5
What does this program print?
height = 65
gender = "female"
if height < 62:
print("You are below average height")
elif height > 69:
print("You are above average height")
else:
print("You are average height")
You are below average height
You are above average height
You are average height
You are below average height
You are above average height
What does this program print?
height = 65
gender = "female"
if height < 62 or (height < 69 and gender == "male"):
print("You are below average height")
elif height > 69 or (height > 62 and gender == "female"):
print("You are above average height")
else:
print("You are average height")
You are below average height
You are above average height
You are average height
You are below average height
You are above average height
What does this program print?
favorite_color = "blue"
if favorite_color != "green":
print("But green is the color of grass!")
if favorite_color == "red":
print("I like red, too!")
if favorite_color == "blue":
print("Blue is the best")
if favorite_color != "yellow":
print("But yellow is the color of school buses!")
But green is the color of grass!
Blue is the best
But yellow is the color of school buses!
But green is the color of grass!
But green is the color of grass!
I like red, too!
Blue is the best
But yellow is the color of school buses!
Blue is the best
