Font size
WorksheetsAll codehs questions on midterm
Total questions: 90
Worksheet time: 45mins
What's wrong with this code
The go function is called twice
The go function has a syntax error
The go function has been defined twice
go is not a command that Karel understands
How many total times will Karel move in this program
1
5
6
7
What is wrong with this for loop?
a: the for loop uses a semicolon(;) instead of colon(:)
b: it should say range(5) instead of range = 5
A
B
A and B
The for loop is correct
What is the proper format for a single line comment in Karel
#This is a comment
//This is a comment
/*This is a comment
This is a comment
What does the mystery function do
Karel moves until it is on a ball
Karel moves once if there is no ball present
Karel moves until it puts down a ball
Karel checks if there is no ball on the current spot and then moves once
Which of the following is not a valid condition to go in an if statement for Karel
balls_present()
front_is_clear()
left_is_blocked()
turn_left()
Say Karel is on a location with one tennis ball. After the following code runs, how many tennis balls will there be at that location?
0
1
2
6
What condition should be used in this while loop to get Karel to pick up all the tennis balls on the current location?
no_balls_present()
balls_present()
front_is_clear()
take_ball()
Why does a programmer indent their code?
Helps show the structure of the code.
Easier for other people to understand.
In Python, it is used to help determine what parts of a code are included in a code block, such as an if statement or for loop.
All of the above
How can we teach Karel new commands?
For loop
While loop
Define a new function
The main function
Say you want to write a program to have Karel put down 300 tennis balls. Which control structure would you use?
If statement
While loop
For loop
Nested while loop
Super Karel starts at Street 1, Avenue 1, facing East in a 5x5 world. What will happen after this code runs?
Karel ends on street 1, avenue 3
Karel ends on street 2, avenue 3
This code won’t run because of a syntax error
Karel will crash into a wall
Karel starts at Street 1, Avenue 1, facing East in a 5x5 world. What will happen after this code runs?
Karel will end on Street 1, Avenue 2
Karel will end on Street 1, Avenue 7
This code won’t run because of a syntax error
Karel will crash into a wall
What is top down design?
Top down design is a way of designing your program by starting with the biggest problem and breaking it down into smaller and smaller pieces that are easier to solve.
Top down design is a way that you can create designs on a computer to put on a web page
Top down design is a way of designing your programs starting with the individual commands first
Top down design is a way to use loops and if statements to decompose the problem
How can we improve this following program?
Break down this program into more functions
Use a for loop to repeat the move command
Use a while loop to repeat the move command
Fix the indentation of this program
In the following code below from the Cleanup Karel example, what is the purpose of If Statement #2?
To move the last time
To pick up the ball that is in the last spot
To pick up the ball that is in the last spot, if there is one
To take the ball from all of the positions that have a ball on them
In the following code, what would be a good Postcondition to write?
Karel is on a spot with a tennis ball facing north
Karel ends one spot above a tennis ball facing East.
Karel is on the same position but on top of a ball.
Karel is facing East.
What is the purpose of using a for loop in code?
To do something if a condition is true
To do something while a condition is true
To repeat something a fixed number of times
To make programs run faster
Which of the following commands is a valid Karel command?
move
move;
move()
move();
What makes the following command an invalid Karel command?
turn_Left()
It should end in semicolon
The L should be a lower l
It should start with a capital T
This command is correct
Which of the following is the correct way to define a turn_right function in Karel?
Why do we use functions in Karel programs?
Break down our program into smaller parts
Avoid repeating code
Make our program more readable
All of the above
If Karel starts at Street 1 and Avenue 1, facing East, where will Karel be, and what direction will Karel be facing after running the following code? (Assume the world is 10x10 in size)
Street 3, Avenue 1, Facing North
Street 1, Avenue 4, Facing North
Street 1, Avenue 3, Facing South
Street 1, Avenue 3, Facing North
Karel starts at Street 1 and Avenue 1, facing East. After calling the stair_step function twice, where will Karel be and what direction will Karel be facing? (assume this is a SuperKarel program and the world is 10x10 in size)
Street 2, Avenue 2, Facing North
Street 3, Avenue 3, Facing East
Street 3, Avenue 3, Facing West
Street 4, Avenue 4, Facing East
In this code, how many times is the dance function called and how many times is it defined?
Called 1 time, defined 1 time
Called 1 time, defined 3 times
Called 3 times, defined 1 time
Called 3 times, defined 3 times
The following code should draw a circle on the screen.
Since we are trying to create a circle, we need to use the create_circle command.
The code will have an error need to define the position when you create the the circle
To add the circle to the canvas, you need to use the circle.add() command
To add the circle to the canvas, you need to use the add(circle) command
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 choices is a properly formed Python variable name, meaning it is both legal in the Python language and considered good style?
user_age
User_Age
user_Age
userAge
If you wanted to use the following code to draw a circle to the canvas with the radius, and x and y coordinates given by the user, how would you ask for this information?
If you were given the following variables:
distance = 2
time = 30
What line of code would print the speed in km/hr if the distance is given in km and the time is given in minutes? (Speed = distance/time)
print(distance/(time/60))
print(distance/time)
print(distance*(time*60))
print(distance*time)
What is printed to the screen when the following program is run?
num = 13 % 3
print(num)
1
2
3
4
What is printed to the screen if the user enters ‘5’ when the following program is run?
5
25
30
50
What does the following program do?
Draws a circle to the center of the canvas with size based on user inputted value
Draws a circle on the canvas with the center positioned at the coordinate (0,0)
Draw a circle on the canvas that is radius distance in the x and y direction from the top left corner
The program contains an error.
If a user enters a diameter value in the variable diameter, how would we use this to draw the correct sized circle?
circle = Circle(diameter)
circle = Circle(diameter, diameter)
circle = Circle(diameter / 2)
circle = Circle(diameter * 2)
A store has 20 apples in its inventory. How can you store this information in a Python variable?
num_apples == 20
20 = num_apples
num_apples = 20
num apples = 20
You want to read input from the user to know how many apples they would like to buy. Which statement should you use to read in a number from the user?
apples_to_buy = input("How many apples would you like? ")
apples_to_buy = print("How many apples would you like? ")
apples_to_buy = int(input("How many apples would you like? "))
apples_to_buy = input_int("How many apples would you like? ")
You are splitting up all of your apples equally between 3 people. Which statement below will calculate how many apples will be left over?
left_over = num_apples / 3
left_over = 3 / num_apples
left_over = num_apples % 3
left_over = 3 % num_apples
In a graphics canvas with a size of WIDTH and a height of HEIGHT, what are the coordinates of the bottom right corner of the window?
0, 0
- HEIGHT / 2, WIDTH / 2
HEIGHT, WIDTH
WIDTH, HEIGHT
In a graphics canvas with a size of WIDTH and a height of HEIGHT, what are the coordinates of the center of the window?
WIDTH, HEIGHT
WIDTH / 2, HEIGHT / 2
0, 0
HEIGHT / 2, WIDTH / 2
In the following code:
What is the meaning of the x variable?
The x coordinate of the left side of a box that would hold the circle
The x coordinate of the right edge of the circle
The radius of the circle
The x coordinate of the center of the circle
Choose the best response: A function passed to an event handler that is called every time a certain event happens is called a _______.
parameterized function.
return function.
callback function.
generator function.
Suppose we’ve written a function draw_square that we want to call every time the mouse is clicked. How can we do this?
add_mouse_click_handler(draw_square)
draw_square(on_mouse_click)
add_mouse_click_handler(draw_square(x, y))
add_mouse_click_handler(draw_square(event))
What does the following code snippet do? Choose the best answer.
This code snippet randomly places black circles on the screen.
This code snippet places a black circle on the screen with a radius of 10 in every place that the mouse is clicked.
This code snippet places a black circle on the screen with a radius of 20 in every place that the mouse is clicked.
This code snippet has an error and will not do anything.
What will be printed from the following:
12.4
12
13.6
4
Which of the following lines of code would be considered the highest level of code?
10110011010011101010
move()
movl $1, %eax
def move():
Which of the following could be considered a computer?
Smart phone
Digital coffee maker
Cars
All of these choices
On the AP Exam, the modulus operator is denoted by MOD. The MOD operator has the same precedence as the * and / operators.
What will c evaluate to in the following code segment?
4
2
18
8
What will the following code segment evaluate to?
1
3
5
10
On the AP exam, INPUT() is used to accept a value from the user, and DISPLAY() is used to display a value. Values that are displayed are NOT started on a new line, but a space is added after the value.
Consider the code segment below.
What is displayed as a result if the user inputs “Rowan” then hits enter into the program?
What is your name? Rowan
Hello
Rowan
What is your name? Rowan
Hello Rowan
What is your name? Rowan
HelloRowan
What is your name? Rowan
Hello name
On the AP exam, the ← operator is used for variable assignment. For example,
a ← 10
assigns the value 10 to the variable a.
The value stored in a variable will always be the most recent value assigned.
Consider the following code segment.
What value is stored in variable c?
12
3
27
c is undefined
What is the last thing printed by the following program?
10
20
30
60
We want to simulate constantly flipping a coin until we get 3 heads in a row and we want the condition to be checked at the start of each iteration. What kind of loop should we use?
For loop
While loop
Loop and a half
Infinite loop
How many times will the following program print "hello"?
10
11
9
This code will loop infinitely
The following code continually asks the user for a password until they guess the correct password, then ends. But there is one problem.
Which of the following will fix this program?
Change the True in line 3 to be password != SECRET_PASSWORD so that the program doesn’t loop infinitely
Change the True in line 3 to be password == SECRET_PASSWORD so that the program doesn’t loop infinitely
Add a break; statement after line 6 so that the program doesn’t loop infinitely
Put line 7 inside of an else statement
What will the following program print when run?
What is the value of the boolean variable can_vote at the end of this program?
True
False
Yes
none, there is a syntax error in this code
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 is printed by the following program?
Is it warm: True
Is it warm: False
Is it warm: yes
Is it warm: no
What is printed by the following program?
Hello, we are open!
Sincerely, the grocery store
Sorry, we are closed!
Sincerely, the grocery store
Hello, we are open!
Sorry, we are closed!
Sincerely, the grocery store
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
We want to print the phrase “CodeHS is the best” exactly 25 times. What kind of control structure should we use?
If statement
While loop
Break statement
For loop
What is the output of the following program?
15
10
0
12345
What will be the output when the following code runs?
logged_in = False
print("User logged in?: " + str(not logged_in))
User logged in?: True
User logged in?: False
True
False
The AP Exam uses the following relational (comparison) operators: =, ≠, >, <, ≥, and ≤.
As well, AND, OR and NOT are used instead of and, or and not.
A comparison using a relational operator evaluates to a Boolean value. For example, a = b evaluates to true if a and b are equal; otherwise, it evaluates to false.
Determine what the following expression would evaluate to.
(9 ≠ 7 AND 17 < 4) OR 65 < 9
yes
true
false
no
The AP Exam uses the following relational (comparison) operators: =, ≠, >, <, ≥, and ≤.
As well, AND, OR and NOT are used instead of and, or and not.
A comparison using a relational operator evaluates to a Boolean value. For example, a = b evaluates to true if a and b are equal; otherwise, it evaluates to false.
Which of the following Boolean expressions is equivalent to the expression?
(a AND b) OR (a AND c)
(a AND b) OR c
(a AND b) AND (a AND c)
(b AND c) OR a
a AND (b OR c)
The AP Exam uses the following relational (comparison) operators: =, ≠, >, <, ≥, and ≤.
As well, AND, OR and NOT are used instead of and, or and not.
In the following code block, assume that the variables rainy and tooCold are boolean.
Which of the following are equivalent to the above code block?
Which of the following returns a random number between 1 and 99?
randint(1, 100)
randint(1, 99)
random.randint(1,99)
random.randint(1,100)
Which of the following could NOT be an output from the following code?
mystery_num = 10 * random.randint(1,10)
print(mystery_num)
50
30
0
90
Which of the following best describes the behavior of this program?
The program correctly displays the sum of all positive integers from 1 to number
The program does not work as intended but rather it displays the number squared.
The program does not work as intended but rather it displays the number factorial.
The program does not work as intended because sum should be initialized to 1.
Which of the following best describes the behavior of this program?
The program does not work as intended because it displays the count of even numbers between 1 and number
The program does not work as intended because it displays count but should instead display i
The program does not work as intended because the condition in the if statement needs to say (number MOD 2 = 1)
The program correctly displays the count of odd numbers between 1 and number
Which of the following best describes the result of running the Mystery procedure?
The result will always be true for any initial value of number
The result will be false whenever the initial value of number is even
The result will always be false for any initial value of number
The result will be false whenever the initial value of number is odd
The AP Exam uses the following relational (comparison) operators: =, ≠, >, <, ≥, and ≤.
As well, AND, OR and NOT are used instead of and, or and not.
A county 911 system uses an automated computer program to dispatch one of two ambulances. In order to dispatch the ambulance, the ambulance needs to be available and the emergency needs to be in the ambulance’s primary zone or the other ambulance is not available.
The following boolean variables are used:
ambOneAvail - set to true if ambulance one is available, otherwise set to false
ambTwoAvail - set to true if ambulance two is available, otherwise set to false
inZone - Set to true if the emergency is in the primary zone for the ambulance, otherwise set to false
Which of the following Boolean expressions can be used in a selection statement to cause ambulance one to be dispatched?
ambOneAvail AND (inZone OR NOT ambTwoAvail)
ambOneAvail AND (inZone OR ambTwoAvail)
ambOneAvail OR (inZone OR ambTwoAvail)
NOT ambTwoAvail AND (inZone OR ambOneAvail)
Which of the following best explains what happens when a new device is connected to the Internet?
A device driver is assigned to the device.
An Internet Protocol (IP) address is assigned to the device.
A packet number is assigned to the device.
A Web site is assigned to the device.
Which of the following activities poses the greatest personal cybersecurity risk?
Making a purchase on an online store that uses public key encryption to transmit information
Paying a bill using a secure online electronic payment system
Purchasing a couch by emailing a credit card number to the couch owner
Checking a bank account on a bank’s website that uses HTTPS for secure communication
Which of the following is LEAST likely to indicate a phishing attack?
An email from a website asks that you click on a link to reset your password.
An email from your bank asks you to call the number on your card to verify a transaction.
An email from your water utility company asks you to enter your date of birth and social security number for verification purposes.
An email indicates you have won money, and asks you to enter your bank account number so the money can be transferred
Which of the following is considered an unethical use of computer resources?
Downloading file sharing software on your home computer
Searching online for the answers to CodeHS exercises and quizzes
Purchasing an app from an app store and downloading it directly to a mobile device
Searching online for an electronic version of a textbook
Which of the following are true statements about digital certificates in Web browsers?
I. Digital certificates are used to verify the ownership of encrypted keys used in secure communication.
II. Digital certificates are used to verify that the connection to a Web site is fault tolerant.
I only
II only
I and II
Neither I nor II
According to the domain name system (DNS), which of the following is a subdomain of the domain example.com?
A user enters a Web address in a browser, and a request for a file is sent to a Web server. Which of the following best describes how the file is sent back to the user
The file is broken into packets and sent over a network. The packets must be reassembled by the user’s computer when they are received. If any packets are missing, the browser re-requests the missing packets.
The file is broken into packets and sent over a network. The user’s browser must request each packet, in order, until all packets are received.
The server attempts to connect directly to the user’s computer. If the connection is successful, the entire file is sent at once. If the connection is unsuccessful, an error message is sent to the user.
The server repeatedly attempts to connect directly to the user’s computer until a connection is made. Once the connection is made, the entire file is sent.
Which of the following is a benefit of the fault-tolerant nature of Internet routing?
The ability to use a hierarchical naming system to avoid naming conflicts
The ability to provide data transmission even when some connections between routers have failed
The ability to resolve errors in domain name system (DNS) lookups
The ability to use multiple protocols such as hypertext transfer protocol (HTTP), Internet protocol (IP), and simple mail transfer protocol (SMTP) to transfer data.
Two computers are built by different manufacturers. One is running a Web server and the other is running a Web browser. Which of the following best describes whether these two computers can communicate with each other across the Internet?
The computers cannot communicate, because different manufacturers use different communication protocols.
The computers can communicate, but additional hardware is needed to convert data packets from one computer’s protocol to the other computer’s protocol.
The computers can communicate directly only if the messages consist of text. Other formats cannot be interpreted across computers.
The computers can communicate directly because Internet communication uses standard protocols that are used by all computers on the Internet.
A city government is attempting to reduce the digital divide between groups with differing access to computing and the Internet.
Which of the following actions is LEAST likely to be effective in this purpose?
Holding basic computer classes at community centers
Providing free wireless Internet connections at locations in low-income neighborhoods
Putting helpful tips for operating computers on the city government website
Requiring that every school and library have assistive devices that allow people with disabilities to access computer resources
An IPv4 address has 32 bits, so there are 232 (over 4 billion) possible IPv4 addresses. Since the Internet is gaining devices quickly, we will soon surpass 232 unique devices on the Internet.
In anticipation of all the new Internet devices, we are in the process of switching to IPv6, which uses 128 bits for a single address. That’s 96 extra bits to represent one address!
Which of the following statements correctly describes how many more addresses will be possible to represent by switching from IPv4 to IPv6?
96 more addresses can be represented with IPv6
296 more addresses can be represented with IPv6
96 times as many addresses can be represented with IPv6
296 times as many addresses can be represented with IPv6
Which of the following would pose the greatest threat to a user’s personal privacy if it were to be leaked to the public?
The IP address of the user’s computer
The user’s browser cookies
The user’s email address
The user’s public key used for encryption
What is a Distributed Denial of Service (DDoS) attack?
An attempt by a government to deny Internet access to its citizens
An attempt to deny access to a website by flooding the website’s servers with millions of requests from different computers
An attempt by one user to deny service to another user by posting malicious material on a social network
An attempt by an Internet user to access private information stored in a private database
Which of the following is a benefit that online shopping websites provide over brick and mortar stores?
Users can try out an item before they buy it
Users can easily pay with cash in person
Users can easily see product reviews and determine if an item has been satisfactory for a large number of people
There is no wait time between purchasing an item and having access to it
Consider the following network diagram:
Each box represents a device connected to the network, each line represents a direct connection between two devices.
Which of the following statements are true about this network:
I - The network is fault tolerant. If one connection fails, any two devices can still communicate.
II - Computers C and E need to first communicate with at least one other device in order to communicate with each other.
I only
II only
I and II
Neither I nor II
