Python_GitHub_Level2_Question9答案——如何输出“回车”

题目

菜农作业:

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)

注意,反斜杠是“\”,不是“/”

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值