0% found this document useful (0 votes)
35 views8 pages

Review Questions: Multiple Choice

Uploaded by

funnyvid289
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views8 pages

Review Questions: Multiple Choice

Uploaded by

funnyvid289
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

122 Chapter 2 Input, Processing, and Output

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

9. A string literal in Python must be enclosed in __________.


a. parentheses.
b. single-quotes.
c. double-quotes.
d. either single-quotes or double-quotes.
10. Short notes placed in different parts of a program explaining how those parts of the
program work are called __________.
a. comments
b. reference manuals
c. tutorials
d. external documentation
11. A(n) __________ makes a variable reference a value in the computer’s memory.
a. variable declaration
b. assignment statement
c. math expression
d. string literal
12. This symbol marks the beginning of a comment in Python.
a. &
b. *
c. **
d. #
13. Which of the following statements will cause an error?
a. x = 17
b. 17 = x
c. x = 99999
d. x = '17'
14. In the expression 12 + 7, the values on the right and left of the + symbol are called
__________.
a. operands
b. operators
c. arguments
d. math expressions
15. This operator performs integer division.
a. //
b. %
c. **
d. /
16. This is an operator that raises a number to a power.
a. %
b. *
c. **
d. /
17. This operator performs division, but instead of returning the quotient it returns the
remainder.
a. %
b. *
c. **
d. /
124 Chapter 2 Input, Processing, and Output

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

š He sold the stock for $42.75 per share.


š He paid his stockbroker another commission that amounted to 3 percent of the amount
he received for the stock.
Write a program that displays the following information:
š The amount of money Joe paid for the stock.
š The amount of commission Joe paid his broker when he bought the stock.
š The amount for which Joe sold the stock.
š The amount of commission Joe paid his broker when he sold the stock.
š Display the amount of money that Joe had left when he sold the stock and paid his
broker (both times). If this amount is positive, then Joe made a profit. If the amount is
negative, then Joe lost money.
13. Planting Grapevines
A vineyard owner is planting several new rows of grapevines, and needs to know how many
grapevines to plant in each row. She has determined that after measuring the length of a
future row, she can use the following formula to calculate the number of vines that will fit
in the row, along with the trellis end-post assemblies that will need to be constructed at
each end of the row:
R 2 2E
V5
S
The terms in the formula are:
V is the number of grapevines that will fit in the row.
R is the length of the row, in feet.
E is the amount of space, in feet, used by an end-post assembly.
S is the space between vines, in feet.
Write a program that makes the calculation for the vineyard owner. The program should
ask the user to input the following:
š The length of the row, in feet
š The amount of space used by an end-post assembly, in feet
š The amount of space between the vines, in feet
Once the input data has been entered, the program should calculate and display the num-
ber of grapevines that will fit in the row.
14. Compound Interest
When a bank account pays compound interest, it pays interest not only on the principal
amount that was deposited into the account, but also on the interest that has accumulated
over time. Suppose you want to deposit some money into a savings account, and let the
account earn compound interest for a certain number of years. The formula for calculating
the balance of the account after a specified number of years is:
A 5 P(1 + nr)
nt

The terms in the formula are:


A is the amount of money in the account after the specified number of years.
P is the principal amount that was originally deposited into the account.
r is the annual interest rate.
n is the number of times per year that the interest is compounded.
t is the specified number of years.
Programming Exercises 129

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.

15. Turtle Graphics Drawings


Use the turtle graphics library to write programs that reproduce each of the designs shown
in Figure 2-34.

Figure 2-34 Designs

North

West East

South

You might also like