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 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)
theint
operator 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 theint
operator 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 assignment
statement 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? 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
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)