| CIT 590 Midterm Exam, Fall 2016 |
Name ______________________________ |
Please keep all answers short and to the point. Do not add information that is not asked for; you will not gain points, but you may lose points if you get it wrong.
| def any_lowercase1(s): for c in s: if c.islower(): return True else: return False |
| def any_lowercase2(s): for 'c' in s: if c.islower(): return 'True' else: return 'False' |
| def any_lowercase3(s): for c in s: flag = c.islower() return flag |
| def any_lowercase4(s): flag = False for c in s: flag = flag or c.islower() return flag |
| def any_lowercase5(s): for c in s: if not c.islower(): return False return True |
Write the header for a method named computer_move
that takes no parameters. |
|
| Write a statement to print "Computer's turn", preceded by a
blank line |
|
Set an integer variable named sum to zero. |
|
Start a loop that will run until sum is 17 or
larger. |
|
Set a variable roll to a random integer between
1 and 6, inclusive. (Assume random has been
imported.) |
|
| Print out a message saying what the computer has just rolled. |
|
| Test if the number rolled is a 1 . . . |
|
| And if it is, return a zero. |
|
| . . . but if it isn't a 1 . . . |
|
Add the number rolled to sum. |
|
| After the loop is finished, print out a message saying how
much the computer has gained this turn. |
|
| Return from the function with the amount gained this turn. |
abc = "abcdefg"
abc[2:4] ?abc[5:] ?abc[:5] ?abc[-3 : -1] ?abc * 3 ?cards = {"ace" : 1, "deuce" : 2, "trey" : 3} for i in cards:
print(i)
format method
to print out a floating point number x with two digits
after the decimal point.Open a file named data.txt for
reading. |
|
| Read in the entire file as a list of lines. |
|
| Close the file. |
a = [1, 2, [3, 4]]
b = a[:]
a[2] = [5, 6]b?squares to a
list of the squares of the numbers 1 through 1000.small is defined as: def small(a, b=5):
return a < b
list(map(small, [1, 2, 3, 4, 5]))
list(filter(small, [1, 2, 3, 4, 5]))
reduce(small, [1, 2, 3, 4, 5])
"Click me" and (2) when clicked, calls the
function clicked().