Editor

Practice questions

Part of Computer Science Principles in Python

131 exam-style questions across the course, each with an explanation of the right answer and the tempting wrong ones.

Unit 1: Programs, variables and errors

Program Design and Testing

Two students are pair programming on a quiz app. Which description matches how pair programming works?

Answers

A team is designing an app that helps students sign up for after-school tutoring. Which two activities are ways to investigate what the app must do? Select two answers.

Select 2 answers.

Answers

A student builds a weather app by first getting the part that downloads today's temperature to work, then adding a five-day forecast, then adding storm alerts. Each part is tested before the next one is added. Which approach does this describe?

Answers

Mia's game uses a collision-detection procedure that she copied from an open-source project. What is the best way for her to acknowledge it?

Answers

The code segment below is meant to display the sum of the values in scores. What happens when it runs?

scores ← [88, 92, 75]
total ← 0
i ← 0
REPEAT 3 TIMES
{
total ← total + scores[i]
i ← i + 1
}
DISPLAY(total)
Answers

The procedure countAtLeast is supposed to return how many values in numList are greater than or equal to target. Which procedure call would reveal that it contains an error?

PROCEDURE countAtLeast(numList, target)
{
count ← 0
FOR EACH num IN numList
{
IF(num > target)
{
count ← count + 1
}
}
RETURN(count)
}
Answers

A program should accept a quantity from 1 to 10, inclusive, and reject anything else. The tester has already tried 1, 5 and 10. Which two additional inputs best check the behavior one step beyond the extremes of the input? Select two answers.

Select 2 answers.

Answers

A video game stores a player's coins in a value that can hold whole numbers from 0 to 65,535. A player with 65,535 coins picks up one more, and the coin counter shows 0. Which kind of error is this?

Answers

Unit 3: Loops and algorithms

Developing Algorithms

What is displayed when this code segment runs?

result ← 4 + 18 MOD 5 * 2
DISPLAY(result)
Answers

What is displayed when this code segment runs?

a ← 3
b ← 8
a ← b
b ← a
DISPLAY(a)
DISPLAY(b)
Answers

Which of the following statements assign the same value to winner as the code segment, for every possible value of points and lives? Select two answers.

Select 2 answers.

IF(points ≥ 50)
{
IF(lives > 0)
{
winner ← true
}
ELSE
{
winner ← false
}
}
ELSE
{
winner ← false
}
Answers

The two code segments look alike. For which starting value of n do they display different values?

Segment I
IF(n MOD 2 = 0)
{
n ← n / 2
}
IF(n MOD 2 = 1)
{
n ← 3 * n + 1
}
DISPLAY(n)
 
Segment II
IF(n MOD 2 = 0)
{
n ← n / 2
}
ELSE
{
n ← 3 * n + 1
}
DISPLAY(n)
Answers

A student creates a new algorithm by combining two procedures that the class wrote and tested earlier. Which of the following are benefits of this approach? Select two answers.

Select 2 answers.

Answers

What is displayed when this code segment runs?

total ← 0
n ← 1
REPEAT 6 TIMES
{
IF(n MOD 3 = 0)
{
total ← total + n
}
n ← n + 1
}
DISPLAY(total)
Answers

Which of the following is NOT an expression?

Answers

Unit 5: Procedures, libraries and simulations

Random Values and Simulations

Which of the following lists every value that RANDOM(2, 5) can return?

Answers

Which of the following describes all the values this code segment could display?

x ← RANDOM(1, 4) * 2 + 1
DISPLAY(x)
Answers

A game should give a player a bonus with a 25% chance. Which of the following conditions are true exactly 25% of the time? Select two answers.

Select 2 answers.

Answers

Which of the following lists all the values this code segment could display?

heads ← 0
REPEAT 3 TIMES
{
IF(RANDOM(1, 2) = 1)
{
heads ← heads + 1
}
}
DISPLAY(heads)
Answers

For which of the following tasks would a computer simulation be most useful instead of a real-world experiment?

Answers

A city builds a simulation of traffic on a planned bridge. To keep it simple, the simulation treats every vehicle as a car and leaves out buses and trucks. Which of the following is the most likely consequence of this choice?

Answers

Which of the following statements about simulations are true? Select two answers.

Select 2 answers.

Answers

Unit 6: Binary and compression

Binary Numbers and Bits

What is the decimal value of the binary number 11001?

Answers

Which binary number is equal to the decimal number 52?

Answers

Which list shows the binary numbers 1011, 110, 1101 and 111 in order from least to greatest?

Answers

What is displayed when this code segment runs?

PROCEDURE toDecimal(bitList)
{
total ← 0
FOR EACH bit IN bitList
{
total ← total * 2 + bit
}
RETURN(total)
}
 
DISPLAY(toDecimal([1, 0, 1, 1]))
Answers

Which of the following statements about representing data with bits are true? Select two answers.

Select 2 answers.

Answers

A game adds 0.1 to a player's speed ten times, starting from 0, and then checks whether the speed equals 1.0. The check comes out false. Which of the following best explains why?

Answers

A phone app records a singer by sampling the sound. Which change would make the recording a closer approximation of the real sound?

Answers

A school gives each of its 1,200 students a unique ID number stored in binary. What is the fewest number of bits that each ID can use?

Answers

Data Compression

A student club keeps a spreadsheet of who has paid their dues and how much. The treasurer wants to compress it before emailing it. Which choice is best?

Answers

A video chat app needs calls to stay smooth for people on slow home connections. Which compression approach fits best?

Answers

Which of the following statements about data compression are true? Select two answers.

Select 2 answers.

Answers

Each image below is stored row by row and compressed with run-length encoding. Which image would most likely shrink the most?

Answers

The code segment below rebuilds a row of pixels from run-length data, where 0 is a white pixel and 1 is a black one. What does the list pixels contain after it runs?

counts ← [3, 1, 2]
colors ← [0, 1, 0]
pixels ← []
i ← 1
REPEAT LENGTH(counts) TIMES
{
REPEAT counts[i] TIMES
{
APPEND(pixels, colors[i])
}
i ← i + 1
}
Answers

Two files of the same size are compressed with the same lossless algorithm. File A shrinks by 80%, and file B shrinks by only 5%. Which of the following best explains the difference?

Answers

A 9,000-bit message is compressed with a lossless algorithm to 3,000 bits. Which statement is true?

Answers

Unit 7: Working with data

Extracting Information from Data

A music streaming app stores millions of songs. Which of the following is metadata for a song?

Answers

A teacher uploads a video of the science fair. Later, she changes its title and deletes its location tag. Which statement is true?

Answers

A study of 200 towns finds that towns with more coffee shops also have more car accidents. Which conclusion is best supported by this finding?

Answers

A town wants to know whether residents support building a skate park. It posts an online survey only on a local skate shop's website and gets 3,000 responses, 95% in favor. Which of the following are true? Select two answers.

Select 2 answers.

Answers

A form asks students to type the name of their state. Which of the following is an example of cleaning the data?

Answers

What is displayed when this code segment runs?

temps ← [72, 85, 90, 64, 88]
count ← 0
FOR EACH t IN temps
{
IF(t ≥ 85)
{
count ← count + 1
}
}
DISPLAY(count)
Answers

Which of the following best describes what this code segment does?

tempsF ← [50, 68, 86]
tempsC ← []
FOR EACH f IN tempsF
{
APPEND(tempsC, (f - 32) * 5 / 9)
}
Answers

A video service wants to find the most-watched show in each state, using billions of viewing records. The records are too large to process on one computer in a reasonable amount of time. Which approach best addresses this challenge?

Answers

Unit 8: The internet

How the Internet Works

A small company invents a new kind of smart speaker. It connects to the Internet without the company asking any other organization for permission. Which of the following best explains why this is possible?

Answers

Which of the following are typically included in a packet's metadata? Select two answers.

Select 2 answers.

Answers

Which of the following best describes the relationship between the Internet and the World Wide Web?

Answers

A network has a bandwidth of 50 megabits per second. What is the least amount of time it can take to send a 200-megabit file over this network?

Answers

In a network, these pairs of devices are directly connected: A and B, A and C, B and D, C and D, D and E. Which of the following is a path from A to E?

Answers

You load the same website twice, a minute apart, and the packets travel through different routers each time. Which of the following best explains this?

Answers

The Internet was designed to be scalable. What does this mean?

Answers

Fault Tolerance and Redundancy

Which of the following best describes a fault-tolerant system?

Answers

In a network, these pairs of devices are directly connected: A and B, A and C, B and C, C and D, D and E, D and F, E and F. If exactly one connection fails, which failure would stop A from communicating with F?

Answers

Use the same network: A and B, A and C, B and C, C and D, D and E, D and F, E and F. Engineers want A to stay able to reach F if any single connection fails. Which of the following changes would do this? Select two answers.

Select 2 answers.

Answers

A school pays for a second Internet connection from a different provider, in case the first one goes down. Which of the following best describes this decision?

Answers

You are loading a web page when a router on the path between your laptop and the web server fails. Which of the following is most likely to happen?

Answers

A city has two cables connecting it to the rest of the Internet. To save money, both cables were laid in the same underground tunnel. Which of the following best describes the vulnerability?

Answers

The two lists below describe a network: the connections are A to B, A to C, B to D, C to D and D to E. What is displayed when the code segment runs?

fromList ← ["A", "A", "B", "C", "D"]
toList ← ["B", "C", "D", "D", "E"]
count ← 0
i ← 1
REPEAT LENGTH(fromList) TIMES
{
IF((fromList[i] = "D") OR (toList[i] = "D"))
{
count ← count + 1
}
i ← i + 1
}
DISPLAY(count)
Answers

Unit 9: Efficiency, limits and parallel computing

Algorithmic Efficiency and Heuristics

Which of the following is an instance of a problem, rather than a general problem?

Answers

Which of the following is an optimization problem?

Answers

Each option describes how many steps an algorithm takes for an input of n items. Which algorithms run in a reasonable amount of time? Select two answers.

Select 2 answers.

Answers

How many times does the statement count ← count + 1 run in this code segment?

count ← 0
REPEAT 5 TIMES
{
REPEAT 4 TIMES
{
count ← count + 1
}
count ← count + 1
}
DISPLAY(count)
Answers

The procedure below is called with a list of n numbers. How many times does total ← total + 1 run?

PROCEDURE countPairs(numbers)
{
total ← 0
FOR EACH a IN numbers
{
FOR EACH b IN numbers
{
total ← total + 1
}
}
RETURN(total)
}
Answers

An algorithm finds the best team by checking every possible group of members in a club of n members. One more person joins the club. What happens to the number of groups the algorithm checks?

Answers

A delivery company plans a route through 60 stops each morning. Checking every possible order of the stops would take far too long. Which approach is most appropriate?

Answers

Which of the following best describes a heuristic?

Answers

Undecidable Problems

Which statement describes a decidable problem?

Answers

A student says: "The halting problem is undecidable, so no program can ever tell whether any particular program stops." What is wrong with this claim?

Answers

Which of these is a decidable problem?

Answers

Which two statements about undecidable problems are true?

Select 2 answers.

Answers

A company advertises a tool that "detects every infinite loop in any program before it runs, with no mistakes." Which response is best?

Answers

What does this program display?

n ← 6
count ← 0
REPEAT UNTIL (n = 1)
{
IF (n MOD 2 = 0)
{
n ← n / 2
}
ELSE
{
n ← 3 * n + 1
}
count ← count + 1
}
DISPLAY (count)
Answers

Parallel and Distributed Computing

A program has four tasks. Tasks P (30 seconds), Q (50 seconds) and R (20 seconds) are independent, and each can run on its own processor at the same time. Task S (10 seconds) can start only after P, Q and R have all finished. What is the least amount of time the program can take?

Answers

A computer has two processors that can work in parallel. It must run four independent tasks that take 20, 30, 40 and 50 seconds. Each task runs on one processor. What is the least amount of time needed to finish all four?

Answers

A task takes 120 seconds when it is run sequentially and 40 seconds when it is run in parallel. What is the speedup of the parallel solution?

Answers

Which of the following statements about parallel computing are true? Select two answers.

Select 2 answers.

Answers

Scientists need to analyze 2 petabytes of telescope images, far more data than a single computer can store. Which approach fits this problem best?

Answers

The list times holds the times, in seconds, of four independent tasks. What is displayed when the code segment runs, and what does it represent?

times ← [15, 40, 25, 10]
total ← 0
longest ← 0
FOR EACH t IN times
{
total ← total + t
IF(t > longest)
{
longest ← t
}
}
DISPLAY(total / longest)
Answers

A program has a sequential portion that takes 30 seconds, and a portion that takes 60 seconds on one processor but can be split evenly among any number of processors. Which of the following statements is true?

Answers

Unit 10: The impact of computing

Effects of Computing

A school's grading app sends parents an alert the moment a new grade is posted. Which statement best describes this effect?

Answers

What was the World Wide Web originally designed to do?

Answers

Which two statements about programmers and the effects of their innovations are accurate? Select two answers.

Select 2 answers.

Answers

A program written to animate 3D movie characters is later adapted by surgeons to rehearse operations on 3D models of patients. What does this example show?

Answers

Which two situations are examples of the digital divide? Select two answers.

Select 2 answers.

Answers

Which statement about the digital divide is accurate?

Answers

The code segment below uses invented broadband rates for four towns. What is displayed?

rates ← [72, 95, 64, 88]
low ← rates[1]
high ← rates[1]
FOR EACH r IN rates
{
IF(r < low)
{
low ← r
}
IF(r > high)
{
high ← r
}
}
DISPLAY(high - low)
Answers

Computing Bias and Crowdsourcing

A company trains a program to rank job applicants using records of the people it hired over the past ten years, most of whom went to the same few colleges. The program now ranks applicants from other colleges lower. What is the most likely cause?

Answers

Which two actions would most help programmers reduce bias in a speech-recognition app? Select two answers.

Select 2 answers.

Answers

Which statement about bias in computing innovations is accurate?

Answers

A hand sensor detects a hand when its reading is at least 45. The list holds the readings from five hands in a group that was under-represented in the training data. What is displayed?

readings ← [52, 38, 61, 44, 35]
count ← 0
FOR EACH r IN readings
{
IF(r ≥ 45)
{
count ← count + 1
}
}
DISPLAY(count)
Answers

Which of these is an example of citizen science?

Answers

Which two are examples of crowdsourcing? Select two answers.

Select 2 answers.

Answers

A musician raises the money for her first album by collecting small pledges from 2,000 fans on a website. Which statement best describes this?

Answers

Legal and Ethical Concerns

Answers
Answers
Answers
Answers
PROCEDURE canShare(isCommercial, isChanged, allowsCommercial, allowsChanges)
{
IF((isCommercial AND NOT allowsCommercial) OR (isChanged AND NOT allowsChanges))
{
RETURN(false)
}
RETURN(true)
}
Answers
Answers
Answers

Safe Computing

Which two are examples of personally identifiable information? Select two answers.

Select 2 answers.

Answers

Kai never posts his address. His public posts do include a photo of his house with the street sign visible, a check-in at the same gym every weekday at 6 a.m., and his school team's jersey. Which risk does this show best?

Answers

Which login process is an example of multifactor authentication?

Answers

Ana sends Ben a message using public key encryption. Which statement is accurate?

Answers

What is the role of a certificate authority?

Answers

A message is stored as a list of numbers from 0 to 25, one per letter. The code segment below encrypts it with a shift of 3. What is displayed?

message ← [7, 24, 2]
key ← 3
FOR EACH n IN message
{
DISPLAY((n + key) MOD 26)
}
Answers

A program secretly installed on a library computer records everything typed on the keyboard, including the passwords people enter. What is this called?

Answers

Which two actions best protect a phone from attacks? Select two answers.

Select 2 answers.

Answers

Unit 12: Exam review

Exam Pseudocode in Python

What is displayed?

aList ← [5, 10, 15, 20]
DISPLAY (aList[2])
Answers

What is displayed?

x ← 0
REPEAT UNTIL (x ≥ 10)
{
x ← x + 4
}
DISPLAY (x)
Answers

What is displayed?

aList ← [1, 2, 3]
bList ← aList
APPEND (aList, 4)
DISPLAY (LENGTH(bList))
Answers

What is displayed?

count ← 7
REPEAT UNTIL (count > 5)
{
count ← count - 1
}
DISPLAY (count)
Answers

Which two Python lines do the same thing as REMOVE(aList, 1)?

Select 2 answers.

Answers

What is displayed?

PROCEDURE mystery(n)
{
IF (n MOD 2 = 0)
{
RETURN (n / 2)
}
RETURN (n * 3)
}
DISPLAY (mystery(4))
DISPLAY (mystery(5))
Answers

Which Python expression gives every value that RANDOM(1, 6) can?

Answers

AP® and Advanced Placement® are trademarks registered by the College Board, which is not affiliated with, and does not endorse, this website.