Font size
WorksheetsCSE Final Exam Review CodeHS
Total questions: 130
Worksheet time: 33hrs 30mins
When the following for loop is complete, how many spaces will Tracy have moved?
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.
Suppose you want to make Tracy draw a mountain range, like the one shown above, starting from the left side.
Which of the following functions would be the most useful function to write in order to solve this problem?
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.
Which of the following statements are true about for loops?
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?
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?
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)
left(360)
Which program below includes no errors?
Which of the following commands can NOT be used to draw one square?
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?
What will be the output of the following program?
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?
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?
forward(200)
backward(200)
forward(201)
backward(201)
Which command will Tracy perform when given the following code?
forward(10)
backward(10)
backward(10)
circle(10)
circle(10)
What will be the output of the following code?
5 circles in a row
4 circles in a row
A slinky with 5 circles
An infinite loop will occur
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.
On which line of code will Python error?
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, 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”.
Fernandez Florence
Florence
Fernandez
FlorenceFernandez
Florence Fernandez
Which of the following statements is true about print statements?
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 is the final result of the expression 4 + 5 * 3?
27
12
21
19
What is the final result of the expression 7 / 3 + 6?
0
8.33333333333
8
0.777777777778
Choose the print statement below that will cause an error. Assume that num has the value 6, and namehas 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”
What does the following program print?
<type 'str'>
<type 'int'>
<type 'float'>
The program crashes and doesn’t print anything.
Suppose you have a variable defined a = "4". What is the variable type of a?
str int float number
str
int
float
number
Choose the option that correctly prints out the variable(s).
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
What does the following code print?
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 will print to the screen when the following program is run?
5
True
<type ‘int’>
<type ‘bool’>
What will print to the screen when the following program is run?
5
False
<type ‘int’>
<type ‘bool’>
What will be the output of this program?
0
5
True
Nothing will print
What will be the output of this program?
0
5
True
Nothing will print
What will be the output of this program?
5
5
-5
5
-5
Nothing will print
What will be the output of this program?
5
5
7
5
7
8
5
8
What will the following program print when run?
Issue Driver’s License
Almost eligible for Driver’s License
No requirements met
Nothing will print
What will the following program print when run?
1
1
3
5
1
4
1
4
5
What will the following program print when run?
1
1
3
5
1
4
1
4
5
What does this program print?
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?
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?
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
What does this program print?
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.
Which of the following for loops would print the following numbers?
Which of the following for loops would print the following numbers?
What is the value of num when this loop completes?
2
8
12
20
Which of the following for loops will give the same values for i as the loop below?
for i in range(10):
for i in range(11, 0):
for i in range(10, 0, -1):
for i in range(0, 10):
for i in range(0, 11, 1):
Three of the for loops below will provide identical values for i. Which for loop will provide values that do not match the others?
for i in range(0, 5):
for i in range(5):
for i in range(0, 5, 1):
for i in range(5, 0, 1):
What does this program print?
It’s still a nice day
It’s still a nice day
It’s still a nice day
It’s still a nice day
It’s still a nice day
It’s still a nice day
It’s still a nice day
It’s still a nice day
It’s still a nice day
It’s still a nice day
It’s still a nice day
It’s still a nice day
It’s still a nice day
It’s still a nice day
Which of the following while loops would continue to loop as long as num has values between the range of 3-12, exclusive?
Which of the following while loops will cause an infinite loop?
When would a while loop be a better control structure to use than a for loop?
When you need to repeat multiple commands
When you need to repeat something 5 times
When you don’t know how many times something will need to repeat
When the user is inputting how many times to repeat something
What will be printed to the screen when this program is run?
0
1
0
1
0
2
0
1
0
1
0
1
1
2
1
2
1
2
What is the value of sum when this loop completes?
8
9
20
0
What will be printed to the screen when this program is run?
100
0
-75
-125
-150
-150
-175
175
What does this program print?
0
1
2
0
1
2
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
0
1
2
3
What is the benefit of using the break command as in the program below?
The user can enter as many answers as they want
The program will break out of the loop as soon as the user enters the magic_number
The loop will prompt the user to enter a number no matter what input they give
The loop will give the magic_number after a certain number of tries
If the user enters ‘4’, I want the loop to exit. Where should the break command be placed in order to end the loop when the user enters this value?
On line 3
On line 5
On line 7
On line 9
Which of the following programs will NOT cause an error?
Which of the programs below will print the following output?
I would like a green balloon.
What will be the output of the following program?
12
code
4
codecodecode
What will be the output of the following program?
Tracy
hello Turtle
Turtle
hello Tracy
What would this program print?
It doesn’t print anything
<>
<><><><>
<><><>
Consider the following functions. Which for loop would print
Fizz
Fizz
for i in range(6): fn_b(i+1)
for i in range(6): fn_a(i) fn_b(i)
for i in range(6): fn_a(i)
for i in range(6): fn_b(i)
What would this program print?
Original Point: 16, 20
Midpoint from Origin: 8, 10
Point: 16, 20
Original Point: 12, 14
Midpoint from Origin: 6, 7
Point: 12, 14
Original Point: 16, 20
Midpoint from Origin: 8, 10
Point: 12, 14
Original Point: 12, 14
Midpoint from Origin: 6, 7
Point: 16, 20
Which of the following options is NOT a valid Python function definition?
What is the output of this program? Assume the user enters “kipp52”, then “baseball45”.
What will be printed when the program below is run?
12
24
50
66
What is the purpose of exceptions?
To indicate that something has gone wrong, and the program does not know how to continue
To point out when the programmer has written exceptionally good code
To tell the user that he/she has given bad data, such as a negative number instead of a positive number
To allow the programmer to write bad code, but have it still work
What will be printed to the screen if the inputs given to the program below are 1.2, -4, hi, 5 ?
Which of the following inputs to the program below would return a print statement containing Your number:
Four
5
3.0
*
What line of code should be written after the function definition to add two single digit values and print the sum?
print get_single_digit() + get_single_digit()
return get_single_digit() + get_single_digit()
print get_single_digit(4) + get_single_digit(5)
print get_single_digit()++
Why do programmers use try and except statements when their code might throw an exception?
So that the programmer can disregard the exception and do what he/she wants anyways
Because Python requires it
To handle exceptions gracefully and either handle the error or print out a useful error message.
Exceptions only are thrown when there are try and exceptstatements. Otherwise, the program will just fail and the programmer will have no idea why it failed.
What kind of data structure is user_data in the following declaration?
user_data = ("TJ", 24, "artLover123")
Tuple
List
String
2d List
What kind of data structure is user_data in the following declaration?
user_data = ["TJ", 24, "artLover123"]
Tuple
List
String
2d List
Which of the following lines of code will cause an error? Use the following definition of ages:
ages = (12, 5, 8)
ages = ages + (1, 3, 5)
print ages[2]
ages = ages[2:]
ages[0] = 3
What does this code snippet print?
fruit = ["b", "n", "n"]
print "a".join(fruit)
bnn
ba na na
banan
banana
What is the value of num after this code runs?
shapes = ["triangle", "square", "hexagon", "circle", "pentagon"]
num = len(shapes)
0
4
5
35
What does this program print?
My favorite animal is a dog or penguin
My favorite animal is a penguin or chipmunk
My favorite animal is a dog penguin chipmunk
My favorite animal is a dog or chipmunk
Which of the following data structures is immutable?
Tuple
List
Dictionary
2d List
What does this program print?
[48, 56, 64, 65, [60, 61, 62]]
[48, 56, 60, 61, 62, 64, 65]
[48, 56, 64, 65, 60, 61, 62]
The program will error.
How many times does this program print That's a large class!?
0
1
4
6
What would the following program print to the screen when run?
7
0
0
d
n
o
B
0
0
7
B
o
n
d
B
o
n
d
0
0
7
700donB
Given the following list: my_list = ["s", "Z", "e", "c", "c", "e", "r", "h", "e", "p", "t"] which program below would give the following output:
Which values entered into ‘my_list’ would print a value of ‘-1’ after the program has run?
5, -10, 6
-10, -5, 6
-5, 10, 6
-5, 0, 10, 6
Which of the following programs would produce the following output:
Which of the following programs would alter my_list to consist of the following:
[‘red’, ‘green’, ‘blue’, ‘orange’, ‘yellow’]
my_list = ['red', 'green', 'blue', 'orange']
my_list.append('yellow')
my_list = ['red', 'green', 'blue', 'orange']
my_list.extend('yellow')
my_list = ['red', 'green', 'blue', 'orange']
my_list.replace('yellow')
my_list = ['red', 'green', 'blue', 'orange']
my_list.add('yellow')
What will be the output of the following program?
[1, 2, 3, 4, 5, 5, 5, 5]
[1, 2, 3, 4, 5]
[1, 2, 3, 4, 6, 7, 8, 9]
[1, 2, 3, 4, 5, 6, 7, 8]
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 raining and 30°F
It is raining and 55°F
It is not raining and 45°F
It is not raining and 50°F
Tracy the Turtle is given the following instructions:
repeat 2 times:
forward 100 units
turn left 120 degrees
forward 100 units
turn left 60 degrees
Given Tracy’s starting point below, what will be the result of running this program code?
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
I and III
II only
I, II and III
Evaluate the mathematical expression: 10 - 6 x (4 - 2) / 2 + 5.
9
10
13
17
If x represents the area of the number line colored blue, which inequality accurately reflects the value of x?
x < 5
x > 5
x ≥ 5
x ≤ 5
What is the result of running this program code?
3
6
10
The program results in an infinite loop
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.
A for loop is used to make decisions between two options and a while loop is used to make decisions between 3 options or more.
A for loop is used when the variable is less than 10 and a while loop is used when the variable is 10 or greater.
A for loop is used when we only need to meet one condition and a while loop is used when there are two or more conditions.
What would the output of the following code be?
x = "Tracy"
print x*5
Tracy5
Tracy Tracy Tracy Tracy Tracy
TracyTracyTracyTracyTracy
x5
How many times would the phrase ‘codeHS’ be printed in the following scenario:
2 times
6 times
8 times
16 times
What is the total forward distance moved when the code below is run?
20
50
100
200
What is the type of the variable x?
x = 5
float
int
str
bool
What would be printed to the screen when the following program is run?
2
3
5
6
What would be the output of the following code?
Yes
No
Maybe
No output
What would be the output of the following code?
[“yellow”, “red”, “orange”, “green”, “blue”]
[“red”, “green”, “blue”, “yellow”, “orange”]
[“yellow”, “blue”, “green”, “red”, “orange”]
[“blue”, “green”, “orange”, “red”, “yellow”]
What would be the output of the following code?
Tracy
Tracy
Turtle
TracyTracy
Turtle
TracyTracy
Turtle
TracyTracy
Turtle
Tracy
Turtle
What will the value of sum be after the following code runs?
6
12
24
0
Which of the following operations will cause an error?
What list is produced using the following list comprehension?
['w', 'w', 'w', 'w', 'w', 'w', 'w', 'w', 'w']
[‘w’, ‘o’, ‘r’, ‘d’]
['b', 'u', 't', 't', 'e', 'r', 'f', 'l', 'y']
['butterfly', 'butterfly', 'butterfly', 'butterfly', 'butterfly', 'butterfly', 'butterfly', 'butterfly', 'butterfly']
What function would you use to get the position of a character in a string?
len
strip
remove
find
Given the following 2D list, which of the following expressions would get the element “cucumber”?
foods[2][1]
foods[1][0]
foods[0][2]
foods[1][1]
What is the value of the list after this program runs?
[‘Mon’, ‘Tues’, ‘Wed’, ‘Thurs’, ‘Fri’, ‘Sat’, ‘Sun’]
[‘Mon’, ‘Tues’, ‘Wed’, ‘Thurs’, ‘Fri’, [‘Sat’, ‘Sun’]]
[‘Fri’, ‘Thurs’, ‘Wed’, ‘Tues’, ‘Mon’, ‘Sat’, ‘Sun’]
[‘Fri’, ‘Thurs’, ‘Wed’, ‘Tues’, ‘Mon’, [‘Sat’, ‘Sun’]]
What is the result of word[-3] if word = “chalkboard”?
o
l
a
r
What is wrong with the following function?
Only one parameter can have a default value given
Any parameters that don’t have default values must come before any parameters that do have default values
Default parameters must be the same type for every parameter
There is nothing wrong with the function
Which of the following boolean expressions would make the while loop find the first animal in the list whose length is longer than 8?
len(animals[cur]) <= 8
len(cur) <= 8
len(animals) <= 8
animals[cur].len <= 8
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?
You have ordered the following item: 3
You have ordered the following item: three
You have ordered the following item:
I’m sorry. You have entered an invalid item
I’m sorry. You have entered an invalid item
