Python 3:如何将输入和字符串添加到同一行?
我必须将输入与字符串放在同一行,但不知道如何操作。 这是代码:
print('Hello! My name is Awesome Computer.')
print('What is your name?')
name = input()
print('It is good to meet you ' + name + '.')
print('How are you today?')
input()
print('Okay.')
print('I am doing great!')
I have to put the input on the same line as the string and can't figure out how.
Here's the code:
print('Hello! My name is Awesome Computer.')
print('What is your name?')
name = input()
print('It is good to meet you ' + name + '.')
print('How are you today?')
input()
print('Okay.')
print('I am doing great!')
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
函数 input() 接受一个要打印的字符串,因此您可以执行以下操作:
它将在接受输入之前打印该字符串,而不添加换行符
The function input() takes in a string to print so you can do this:
And it will print the string before taking input without adding a newline
您可以像下面一样将一个字符串放入输入函数参数中,它将打印该字符串并在同一行获取输入。此外,您的第二个输入函数调用没有保存到变量中。
You can put a string into the input function parameters like I did below and it will print the string and get the input on the same line. Also, your second input function call wasn't being saved into a variable.
测试结果
Test Results