.在 python 中获取和使用输入的正确方法是什么,特别是询问某人的名字,然后在代码中使用它?

. What is the correct way to get and use inputs in python specifically asking someone's name and then using it in the code?

我收到了我的意见:

name = input("what is your name? ") 

但事实证明,使用该输入有点困难。

 name = input('Enter in your name: ')
 age = input('Hello, ' + name + '. What is your age? ')

非常感谢 qwertee 的帮助。

name = input('Enter in your name: ')
print('Hello, ' + name)

您缺少最后的 ),不需要最后的 +"。将 "Hello," + " " 缩短为 "Hello, "

也更容易

编辑:不确定这是否是您想要的,但这是您添加另一部分的方式:

name = input('Enter in your name: ')
age = input('Hello, ' + name + '. What is your age? ')

您可以通过将 name 分配给输入来询问他们的名字。要在 print 中使用名称,只需添加不带引号的 + name + 'name' 只会打印单词名称。你对 age 做同样的事情:将它分配给一个输入,可能在它说 hello [name] 之后。然后在下一个 print/input 中使用它,您只需添加 + str(age) 不带引号到 return 该值。

如果您想进一步说明,请询问 :)