- (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).
# Date Conversion
inputStr = "2014/10/21"
year, month, day = inputStr.split("/")
print("今年是民國", year - 1911, "年")
- (10%)
Suppose that you created a file "hello.txt" using "nano" with the
following contents:
123456789012
Hello, NCNU.
Hello
NCNU
What will be the output by running the following code?
# Word, line, and character count
Infile = open("hello.txt", "r")
s = Infile.read()
print( len(s) )
Infile.close()
- (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(1, 5):
s = "{0:>" + str(i) + "}"
print(i, s, s.format("*") )
- (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 Justification
for i in range(1,10, 2):
print( "{0:^9}".format( '*' * i ) )