Review Questions: Multiple Choice
Review Questions: Multiple Choice
Review Questions
Multiple Choice
1. A __________ error does not prevent the program from running, but causes it to
produce incorrect results.
a. syntax
b. hardware
c. logic
d. fatal
2. A __________ is a single function that the program must perform in order to satisfy
the customer.
a. task
b. software requirement
c. prerequisite
d. predicate
3. A(n) __________ is a set of well-defined logical steps that must be taken to perform a task.
a. logarithm
b. plan of action
c. logic schedule
d. algorithm
4. An informal language that has no syntax rules and is not meant to be compiled or
executed is called __________.
a. faux code
b. pseudocode
c. Python
d. a flowchart
5. A __________ is a diagram that graphically depicts the steps that take place in a
program.
a. flowchart
b. step chart
c. code graph
d. program graph
6. A __________ is a sequence of characters.
a. char sequence
b. character collection
c. string
d. text block
7. A __________ is a name that references a value in the computer’s memory.
a. variable
b. register
c. RAM slot
d. byte
8. A __________ is any hypothetical person using a program and providing input for it.
a. designer
b. user
c. guinea pig
d. test subject
Review Questions 123
18. Suppose the following statement is in a program: price = 99.0. After this statement
executes, the price variable will reference a value of which data type?
a. int
b. float
c. currency
d. str
19. Which built-in function can be used to read input that has been typed on the keyboard?
a. input()
b. get_input()
c. read_input()
d. keyboard()
20. Which built-in function can be used to convert an int value to a float?
a. int_to_float()
b. float()
c. convert()
d. int()
21. A magic number is ________________.
a. a number that is mathematically undefined
b. an unexplained value that appears in a program’s code
c. a number that cannot be divided by 1
d. a number that causes computers to crash
22. A __________ is a name that represents a value that does not change during the pro-
gram’s execution.
a. named literal
b. named constant
c. variable signature
d. key term
True or False
1. Programmers must be careful not to make syntax errors when writing pseudocode
programs.
2. In a math expression, multiplication and division take place before addition and
subtraction.
3. Variable names can have spaces in them.
4. In Python, the first character of a variable name cannot be a number.
5. If you print a variable that has not been assigned a value, the number 0 will be displayed.
Short Answer
1. What does a professional programmer usually do first to gain an understanding of a
problem?
2. How does pseudocode differ from actual code written in a programming language?
3. Computer programs typically perform what three steps?
4. What rules and considerations should influence the names given to variables in a
program?
5. What is the difference between floating-point division and integer division?
6. What is a magic number? Why are magic numbers problematic?
Review Questions 125
7. Assume a program uses the named constant PI to represent the value 3.14159. The
program uses the named constant in several statements. What is the advantage of using
the named constant instead of the actual value 3.14159 in each statement?
Algorithm Workbench
1. Write Python code that prompts the user to enter his or her age and assigns the user’s
input to an integer variable named age.
2. Write Python code that prompts the user to enter his or her favorite color and assigns
the user’s input to a variable named color.
3. Write assignment statements that perform the following operations with the variables
a, b, and c:
a. Adds 2 to a and assigns the result to b
b. Multiplies b times 4 and assigns the result to a
c. Divides a by 3.14 and assigns the result to b
d. Subtracts 8 from b and assigns the result to a
4. Assume the variables result, w, x, y, and z are all integers, and that w = 5, x = 4,
y = 8, and z = 2. What value will be stored in result after each of the following
statements execute?
a. result = x + y
b. result = z * 2
c. result = y / x
d. result = y – z
e. result = w // z
5. Write a Python statement that assigns the product of 10 and 15 to the variable product.
6. Write a Python statement that subtracts the variable down_payment from the variable
total and assigns the result to the variable due.
7. Write a Python statement that multiplies the variable subtotal by 0.15 and assigns
the result to the variable total.
8. What would the following display?
a = 5
b = 2
c = 3
result = a + b * c
print(result)
9. What would the following display?
num = 99
num = 5
print(num)
10. Assume the variable sales references a float value. Write a statement that displays
the value rounded to two decimal points.
11. Assume the following statement has been executed:
number = 1234567.456
Write a Python statement that displays the value referenced by the number variable
formatted as
1,234,567.5
12. What will the following statement display?
print('X\tO\tX\nO\tX\tO\nX\tO\tX\n')
126 Chapter 2 Input, Processing, and Output
13. Write a turtle graphics statement that draws a circle with a radius of 75 pixels.
14. Write the turtle graphics statements to draw a square that is 100 pixels wide on each
side and filled with the color blue.
15. Write the turtle graphics statements to draw a square that is 100 pixels wide on
each side and a circle that is centered inside the square. The circle’s radius should be
80 pixels. The circle should be filled with the color red. (The square should not be
filled with a color.)
Programming Exercises
1. Personal Information
Write a program that displays the following information:
š Your name
š <RXUDGGUHVVZLWKFLW\VWDWHDQG=,3
š Your telephone number
š Your college major
2. Sales Prediction
A company has determined that its annual profit is typically 23 percent of total sales. Write
a program that asks the user to enter the projected amount of total sales, then displays the
VideoNote
The Sales
profit that will be made from that amount.
Prediction Problem
Hint: Use the value 0.23 to represent 23 percent.
3. Pounds to Kilograms
One pound is equivalent to 0.454 kilograms. Write a program that asks the user to enter
the mass of an object in pounds and then calculates and displays the mass of the object in
kilograms.
4. Total Purchase
A customer in a store is purchasing five items. Write a program that asks for the price of
each item, then displays the subtotal of the sale, the amount of sales tax, and the total.
Assume the sales tax is 7 percent.
5. Distance Traveled
Assuming there are no accidents or delays, the distance that a car travels down the inter-
state can be calculated with the following formula:
Distance 5 Speed 3 Time
A car is traveling at 70 miles per hour. Write a program that displays the following:
š The distance the car will travel in 6 hours
š The distance the car will travel in 10 hours
š The distance the car will travel in 15 hours
6. Payment Instalments
Write a program that asks the user to enter the amount of a purchase and the desired
number of payment instalments. The program should add 5 percent to the amount to get
the total purchase amount, and then divide it by the desired number of instalments, then
Programming Exercises 127
display messages telling the user the total amount of the purchase and how much each
instalment will cost.
7. Miles-per-Gallon
A car's miles-per-gallon (MPG) can be calculated with the following formula:
MPG 5 Miles driven 4 Gallons of gas used
Write a program that asks the user for the number of miles driven and the gallons of gas
used. It should calculate the car's MPG and display the result.
8. Tip, Tax, and Total
Write a program that calculates the total amount of a meal purchased at a restaurant. The
program should ask the user to enter the charge for the food, then calculate the amounts
of a 18 percent tip and 7 percent sales tax. Display each of these amounts and the total.
9. Circle Measurements
Write a program that asks the user to enter the radius of a circle. The program should cal-
culate and display the area and circumference of the circle using πr2 for the area and 2πr
for the circumference.
Hint: You can either use 3.14159 as the value of pi (π), or add the statement "import math"
to the start of the program and then use "math.pi" wherever you need the value of pi in
the program.
10. Ingredient Adjuster
A cookie recipe calls for the following ingredients:
š 1.5 cups of sugar
š 1 cup of butter
š 2.75 cups of flour
The recipe produces 48 cookies with this amount of the ingredients. Write a program that
asks the user how many cookies he or she wants to make, then displays the number of cups
of each ingredient needed for the specified number of cookies.
11. Male and Female Percentages
Write a program that asks the user for the number of males and the number of females regis-
tered in a class. The program should display the percentage of males and females in the class.
Hint: Suppose there are 8 males and 12 females in a class. There are 20 students in the
class. The percentage of males can be calculated as 8 ÷ 20 = 0.4, or 40%. The percentage
of females can be calculated as 12 ÷ 20 = 0.6, or 60%.
12. Stock Transaction Program
Last month, Joe purchased some stock in Acme Software, Inc. Here are the details of the
purchase:
š The number of shares that Joe purchased was 2,000.
š When Joe purchased the stock, he paid $40.00 per share.
š Joe paid his stockbroker a commission that amounted to 3 percent of the amount he paid
for the stock.
Two weeks later, Joe sold the stock. Here are the details of the sale:
š The number of shares that Joe sold was 2,000.
128 Chapter 2 Input, Processing, and Output
Write a program that makes the calculation for you. The program should ask the user to
input the following:
š The amount of principal originally deposited into the account
š The annual interest rate paid by the account
š The number of times per year that the interest is compounded (For example, if interest
is compounded monthly, enter 12. If interest is compounded quarterly, enter 4.)
š The number of years the account will be left to earn interest
Once the input data has been entered, the program should calculate and display the amount
of money that will be in the account after the specified number of years.
NOTE: The user should enter the interest rate as a percentage. For example, 2 percent
would be entered as 2, not as .02. The program will then have to divide the input by
100 to move the decimal point to the correct position.
North
West East
South