Date: December 3, 2013
Time: 14:10-16:00
Open book; turn off computer & mobile phone
(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 a:
while i > 0:
print('*', end='')
i = 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).
# Modifying a List
aList = [0] * 6
sequence = "1 2 3 4 5 1 3 5"
for i in sequence.split():
aList[i] = aList[i] + 1
for i in aList:
print(i, end=' ')
# Loop Structure
for i in range(10):
if i == 3: break
print(i)
print(i)