NEW
Font size
WorksheetsComputer Science Essentials Semester Exam 2021
Total questions: 60
Worksheet time: 15hrs 0mins
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.
# 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.
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?
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
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)
circle
hexagon
triangle
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?
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).
10, 20, 30, 40, 50
10, 15, 20, 25, 30, 35, 40, 45, 50, 55
10, 55, 10
10, 20, 30, 40, 50, 55
Remember % is the remainder operator.
forward(200)
backward(200)
forward(201)
backward(201)
forward(10)
backward(10)
backward(10)
circle(10)
circle(10)
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?
**remember your order of operations
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”
<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
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
3.4
4.4
3
4.4
3
4
This 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
This is not a valid Python operation.
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.
Line 1
Line 2
Line 3
Line 4
A, B, C, D
B, C, A, D
A, C, D, B
C, B, A, D
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
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.
5
True
<type ‘int’>
<type ‘bool’>
5
True
<type ‘int’>
<type ‘bool’>
0
5
True
Nothing will print
0
5
True
Nothing will print
5
5
-5
5
-5
Nothing will print
5
5
7
5
7
8
5
8
Issue Driver’s License
Almost eligible for Driver’s License
No requirements met
Nothing will print
1
1
3
5
1
4
1
4
5
1
1
3
5
1
4
1
4
5
You are below average height
You are above average height
You are average height
You are below average height
You are above 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
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
