(10%)
Determine whether the following code is correct or not. If it is
correct, predict its output. If it is incorrect, point out the
mistake(s).
# Simultaneous Assignment a, b, c = 1, 2, 3
for i in range(10):
a, b, c = b, c, a
print(a, b, c)
(10%)
Determine whether the following code is correct or not. If it is
correct, predict its output. If it is incorrect, point out the
mistake(s).
# String Length s = "HELLO\n\nNCNU\n"
print(len(s), ord(s[-1]))
(10%)
Determine whether the following code is correct or not. If it is
correct, predict its output. If it is incorrect, point out the
mistake(s).
# String Slicing N = 5
s = " "*(N-1)+"+"+" "*(N-1)
for i in range(N-1):
print( s[ i : i+N ] )
for i in range(N-1, -1, -1):
print( s[ i : i+N ] )
(10%)Determine whether the following code is correct or not. If it is
correct, predict its output. If it is incorrect, point out the
mistake(s).
# Indexing means to retrieve a character from a string with its index number aList = ["###", "--#", "###", "#--"]
for i in range(8):
print( aList[i % 4] )
(10%)
Determine whether the following code is correct or not. If it is
correct, predict its output. If it is incorrect, point out the
mistake(s).
# Dynamically create a template string
for i in range(8):
s = "{0:" + "><"[i % 2] + "3}"
print( s.format("#") )