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
booleanoperands - All of the above
- None of the above
(3) _____In Pyhthon, 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(d)theintoperator is a/an:- Assignment operator
- Relational operator
- Typecast operator
- All of the above
- None of the above
(7) _____In the Python statement i = int(4.0)the operand of theintoperator is a/an:- Assignment operator
- Literal
- Typecast operator
- All of the above
- None of the above
(8) _____In Python, what kind of statement is i = 0?- Boolean statement
- Declaration statement
- Typecast statement
- All of the above
- None of the above
(9) _____In Python, an assignmentstatement must contain which of the following?- Curly brackets
- Parentheses
- An equal sign
- All of the above
- None of the above
(10) _____In Python, what is returned from a function by default? floatintstr- 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
| Actual parameters and formal parameters |
|
|
| Declaration and assignment |
|
|
float and int |
|
|
| binary operator and unary operator |
|
|
| program and function |
|
|
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 a call to a function named sales_tax() (that is passed a float actual parameter named price) to a variable named tax. |
|
|
Displays the value of a variable named 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"""
def get_digit(n):
result = int(n // 10)
return result
def func2(n):
result = int(n % 100)
return result
if __name__ == "__main__":
digit2 = 0
digit3 = 0
num1 = 1882
num2 = 4132
num3 = 71
num1 = func2(num1)
num2 = func2(num2)
num3 = func2(num3)
digit1 = get_digit(num1)
digit2 = get_digit(num2)
digit3 = get_digit(num3)
print("Digits: ", digit1, digit2, digit3)