I've basically made a def function to ask user's name with the input but when I tried to make an input to get the user's name accordingly, I came to realise that each input has to be assigned individually so as to later print that input linked according to what the user inserted their name.
我基本上做了一个def函数来用输入询问用户的名字,但当我尝试输入以获得相应的用户名时,我意识到每个输入都必须单独分配,以便以后打印输入链接根据用户插入的名称。
## Ask user's name with the use of def function.
def asking_username():
print("What's your name? ")
username = input()
return username
print("Hello, " + asking_username().title() + "!")
The code above that I made has no problem, but I'd like to make the input to get an user insert in the same line as the print("What's your name? ").
我上面的代码没有问题,但我想做一个输入,让用户插入与print相同的行(“你叫什么名字?”)。
How do you individually assign each input so that it does not get confused with the other input in case multiple inputs are inserted?
如何单独分配每个输入,以便在插入多个输入时不会与其他输入混淆?
1 个解决方案
#1
0
How about:
怎么样:
username = input("Enter your name\n")
This works, because I'm using the newline character ("\n"
).
这是有效的,因为我正在使用换行符(“\ n”)。
#1
0
How about:
怎么样:
username = input("Enter your name\n")
This works, because I'm using the newline character ("\n"
).
这是有效的,因为我正在使用换行符(“\ n”)。