Midterm Exam (2)
|
|
Date: November 9, 2016 |
(10%) Determine whether the following code has syntax errors or not. If it is correct, predict its output. If it is incorrect, point out the mistake(s).
# Pass by Value
def main():
aList = [9, 2, 3]
print(aList)
print_star( aList )
# print(aList)
def print_star( a ):
for i in range( len(a) ):
while a[i] > 0:
print('*', end='')
a[i] = a[i] - 1
print()
main()
(10%) Determine whether the following code has syntax errors or not. If it is correct, predict its output. If it is incorrect, point out the mistake(s).
# Caesar Cipher
message = "FLWJJRJSY"
key = 21
for ch in message:
print( chr( ( ( ord(ch) + key - 65) % 26 ) + 65 ), end='' )
print()
# Loop Structure
i = 1
while i < 10:
if i == 7: break
else:
i = i + 1
print(i)
print(i)