Midterm Exam (1)
|
|
Date: October 12th, 2016 |
(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
str = "ALICE"
n = len(str)
for i in range(n):
print(str[-i], sep='')
(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
first = "Brad"
last = "Pitt"
print(first[-1:] + last[-1])
# Stars
N = 5
str = ' '*(N-1) + '*'*N
for i in range(N):
print( str[i : i+N] )