0% found this document useful (0 votes)
84 views4 pages

Chapter 2 Review Questions

The document contains review questions about programming concepts like data types, variables, operators, and functions. It also includes examples of coding tasks like taking user input, performing calculations, and using turtle graphics to draw shapes. The questions cover a range of foundational programming topics.

Uploaded by

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

Chapter 2 Review Questions

The document contains review questions about programming concepts like data types, variables, operators, and functions. It also includes examples of coding tasks like taking user input, performing calculations, and using turtle graphics to draw shapes. The questions cover a range of foundational programming topics.

Uploaded by

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

Chapter 2 Review Questions

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)__________isasetofwell-definedlogicalstepsthatmustbetakentoperformatask. 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
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. /
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. Whichbuilt-infunctioncanbeusedtoreadinputthathasbeentypedonthekeyboard? 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. Ifyouprintavariablethathasnotbeenassignedavalue,thenumber0willbedisplayed.
Short Answer
1. What does a professional programmer usually do first to gain an understanding of a problem?
2. What is pseudocode?
3. Computer programs typically perform what three steps?
4. If a math expression adds a float to an int, what will the data type of the result be?
5. What is the difference between floating-point division and integer division?
6. What is a magic number? Why are magic numbers problematic?
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 height and assigns the user’s input
to a variable named height.
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 sum of 10 and 14 to the variable total.
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('George', 'John', 'Paul', 'Ringo', sep='@')
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.)

You might also like