Mid-term Exam (2)
|
|
Date: December 10, 2013 |
(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).
# Pass by Value
def main():
aList = [1, 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 erros or not. If it is correct, predict its output. If it is incorrect, point out the mistake(s).
# Modify a List
aList = [0] * 6
sequence = "2 4 6 1 2 3 4 5"
for j in sequence.split():
i = eval(j)
aList[i] = aList[i] + 1
for i in aList:
print(i, end=' ')
# Loop Structure
i = 1
while i < 10:
if i == 3: break
else:
i = i + 1
print(i)
print(i)