CSC 127A - Exam1
ISTA130 Practice Midterm Fall 11 Section Leader_______ Name____________________________150pts
1. Write an X To the left of each valid Python names (identifiers). (6pts)
a) _ X_ misPelted e) _ X_ t_rex
b) _ X_ ident999 f) ___ ???
c) ____ 25or6to4 g) ___ H.P.
2. Write an X To the left of each Python reserved words (keywords). (6pts)
a) ___ UofA e) _ X_ False
b) ___ mercer f) ___ J.C Penney
c) ___ false g) _ X_ def
3. For each Python expression, indicate its value in the space to its left. Be sure to write a resulting value of the appropriate type. For example, 2.0 is different than 2 which is also different than '2'. (14pts)
a) ___10___ 5 * 2 i) ___9___ 8 + 4 // 3
b) ___2___ 5 // 2 j) ___4___ 2 + (int)(14.0 / (3 + 4.0 ))
c) __2.5___ 5 / 2 k) __123__ eval('123') // Hardcopy was missing ' '
e) ___7____ 5 + 2 l) __1.23__ eval('1.23')
f) __7.0___ 5 + 2.0 m) __123.0__ float(123)
g) __'52'___ '5' + '2' n) ___0____ 10 % (4 + 6) / 2
h) __25____ 5**2 o) __0.2___ 1234567 % 2 / 5.0
4. Write the output that would be printed from each of the following code fragments. (6pts)
| | | |
|x = 5 |a = 5 |for i in range(3): |
|y = 7.3 |b = 4 |print(i, end=' ') |
|print('Answer', x + y) |temp = a | |
| |a = b | |
|12.3 |b = temp |0 1 2 |
| |print(a, b, temp) | |
| | | |
| |4 5 5 | |
| | | |
5. For each Python expression, indicate its value in the space to its left. Be sure to list a resulting value of appropriate type. For example, 2.0 is different than 2. Assume import math (4pts)
a) ___2.0__ math.sqrt(4.0) c) ___3____ round(3.45678)
b) ____3___ round(math.pi) d) __6.79__ round(6.78999, 2)
6) Write the complete dialog (input and output) from this program when the user enters 56 (4pts)
Write user input and program output here:
number = int(input('Number? '))
number = number // 10 Number? 56
number = number % 3 2
print(number)
7) Write a complete Python program that reads an integer representing change to return and prints how many dimes (10 cents) and pennies will make that change. You only have dimes and pennies to return, no quarters or nickels. Use the given dialog to guide your algorithm and code. (8pts)
Change? 97
Dimes: 9
Pennies: 7
# Write the complete program below this line. Do not use def main():
change = int(input('Change? '))
dimes = change // 10
pennies = change % 10
print('Dimes:', dimes)
print('Pennies:', pennies)
8. Write the output generated by the following code. (4pts)
j, k = 0, 1
if j != k:
print('abc')
if j == k:
print('def') abc
if j = k:
print('klm')
9. For each Python expression, write True if the expression evaluates to true. Write False if the expression evaluates to false. Assume the following variables always have the values shown. (8pts)
s = 'euclid'
n = 5
x = 100.0
a) __True___ n == 5 e) ___True______ s > 'any' and s < 'zero'
b) __False__ x - 1.0 > n + 999 f) ___False_____ not(s == 'euclid')
c) __True___ x = 0.0 g) ___True______ s[0] == 'e' and s[2] == 'c'
d) __True___ x != n h) ___ False_____ s[1:3] == 'ucl'
10. Given 2 integers, complete function in3050 to return true if both arguments are in the range 30..40 inclusive, or they are both in the range 40..50 inclusive. (10pts) returns
in3050(30, 31) returns True
in3050(40, 50) returns True
in3050(39, 49) returns False
in3050(30, 41) returns False
def in3050(a, b):
range1 = 30 ................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.