题目
菜农作业:
Question 9 | |
Level 2 | |
Question£º | |
Write a program that accepts sequence of lines as input and prints the lines after making all characters in the sentence capitalized. | |
Suppose the following input is supplied to the program: | |
Hello world | |
Practice makes perfect | |
Then, the output should be: | |
HELLO WORLD | |
PRACTICE MAKES PERFECT |
难点:输入多行内容
众所周知,input()只能输入一行,实现多行可以用循环。我用的while true.
那么如何跳出循环?
我选择让用户只输入一个空格,就跳出循环,输出内容,代码如下:
b = ""
while True:
a = input()
b += (str.upper(a))
b += "\n"
# \r : return the first letter of the string
# 怎么输出回车
if a == " ":
break
print(b)
注意,反斜杠是“\”,不是“/”