如何获得用户输入?蟒蛇

时间:2018-10-06 13:08:39

标签: python user-input

我对此很陌生,所以请保持温柔!

作为Python课程的一些工作,我正在学习运行用户输入代码。我将以下代码放在一起,但是当我使用Command-B运行它时,它问我“你叫什么名字?”问题,但是当我输入我的名字并单击Enter时,什么也没发生?有关信息,我正在使用Python 3.7和SublimeText。

我100%肯定这是一个简单的答案,但是令人惊讶的是我找不到答案,而且我在这里(通常是通过Google等)进行了一些搜索。

name=input("What's your name?:")
print("Hi",name,"how do you do.")
age=input("How old are you",name,"?:")
print("Great",name,"I'm",age,"years old too.")
city=input("Which city do you come from",name,"?:")
print("What a coincidence, I am from",city,"too.")
print(name,", here is your record //")
print(name, age, city)

感谢您的帮助,如果你们有超级新手的提示,将不胜感激!

2 个答案:

答案 0 :(得分:1)

您遇到了一些问题,因为您几乎没有语法错误。以下是带有更正的代码。你去了:

name = input("What's your name?:")
print("Hi "+ name + " how do you do.")
age = input("How old are you " + name + " ?:")
print("Great " + name + "I'm " + age + " years old too.")
city = input("Which city do you come from " + name + " ?:")
print("What a coincidence, I am from " + city + " too.")
print(name + " , here is your record //: ")
print(name + " " + age + " " + city)

学习Python祝您好运:)

答案 1 :(得分:-1)

 name=input("What's your name?:")
 print("Hi"+name+"how do you do.")
 age=input("How old are you "+name+" ?:")
 print("Great "+name," I'm ",age+" years old too.")
 city=input("Which city do you come from "+name+" ?:")
 print("What a coincidence, I am from "+city+" too.")
 print(name+", here is your record //")
 print(name+age+city)

使用+print内进行串联