Mid-term Exam (1)
|
|
Date: October 28, 2014 |
How can a man die better
than facing fearful odds
for the ashes of his fathers
and the temples of his Gods
(10%) Determine whether the following code has syntax erros or not. If it is correct, predict its output. If it is incorrect, point out the mistake(s).
# Caesar Cipher
message = "KDWKDZDB"
key = 23
for ch in message:
print( chr( ( ( ord(ch) + key - 65) % 26 ) + 65 ), end='' )
print()
(10%) Determine whether the following code has syntax erros or not. If it is correct, predict its output. If it is incorrect, point out the mistake(s).
# Indexing and Slicing
def main():
first = "Anne"
last = "Hathaway"
print(first[-1:] + last[-1])
main()
# Dice Rolling
count = [ 0, 1, 1, 2, 4, 2 ]
for n in [1, 2, 2, 3, 5, 3 ]:
count[n-1] = count[n-1] + 1
for i in range(6):
print( i+1 , '*' * count[i] )