Practice exam 1
Written Portion of Exam 1 - Sample
3. (10 points) Provide a concrete example of each of the following (in Python). If appropriate, you may use the same example more than once.
Answer all of the following questions. This is a "closed book" examination and you must work entirely on your own.
-
- (10 points) Choose the best answer to each of the following:
(1) _____
In Python, +
is- A relational operator
- A unary operator
- A boolean operator
- All of the above
- None of the above
(2) _____
In Python, -1 the - is - A unary operator
- A binary operator
- Has
boolean
operands - All of the above
- None of the above
(3) _____
In Python, a variable is - The implicit loss of precision in arithemtic operations
- The way the decrement operator changes
- A named space for holding a value
- All of the above
- None of the above
(4) _____
In Python, the statement float cost
- Will cause a logic error
- Will cause a run-time error
- Will cause a repetitive stress error
- All of the above
- None of the above
(5) _____
In the Python statement i = int(d)
the operator=
is a/an:- Assignment operator
- Relational operator
- Typecast operator
- All of the above
- None of the above
(6) _____
In the Python statement i = int(4.0)
the operand of theint
operator is a/an:- Assignment operator
- Literal
- Typecast operator
- All of the above
- None of the above
(7) _____
In Python, what kind of statement is i = 0
?- Boolean statement
- Declaration statement
- Typecast statement
- All of the above
- None of the above
(8) _____
In Python, an assignment
statement must contain which of the following?- Curly brackets
- Parentheses
- An equal sign
- All of the above
- None of the above
(9) _____
In Python, what is the default type for a variable set by an input statement? float
int
str
- None
- All of the above
- (10 points) Choose the best answer to each of the following:
3 * 4 * 2 |
|
3 * 4 + |
|
2 + 3 + 4 * 5 |
|
2 + 3 +* 4 * 5 |
|
Logic Error
Run-time error
Style error
Syntax error
+= and = |
|
Declaration and assignment |
|
float and int |
|
binary operator and unary operator |
|
integer division and division |
|
Declares price to be an int variable set to 5. |
|
Assigns the value 40.99 to a variable named price . |
|
Reduces a variable named price by 10 percent. |
|
Assigns the result of an input statement of "Enter tax" to a variable named sales_tax . |
|
Displays the value of a variable named sales_tax on the console (i.e., standard output) with two tab character in front of it. |
|
6. (5 points) Show what will be printed by the following application (assuming it is compiled and executed properly).
"""Digit Checker"""
digit2 = 0
digit3 = 0
num1 = 1882
num2 = 4132
num3 = 71
num1 = int(num1 % 100)
num2 = int(num2 % 100)
num3 = int(num3 %100)
digit1 = int(num1 // 10)
digit2 = int(num2 // 10)
digit3 = int(num3 // 10)
print("Digits: ", digit1, digit2, digit3)