我对此很陌生,所以请温柔一点!
作为我的Python课程的一点工作,我正在学习运行用户输入代码。我把下面的代码放在一起,但是当我使用命令-B运行它时,它会问我"你叫什么名字?"问题,但是当我输入我的名字并单击回车时,没有任何反应?有关信息,我正在使用Python 3.7和SublimeText。
我 100% 确定这是一个简单的答案,但令人惊讶的是我找不到答案,我在这里搜索了一点,通常是通过谷歌等。
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)
感谢您的任何帮助,如果你们对超级新手有提示,将不胜感激!
您遇到了一些问题,因为您几乎没有语法错误。以下是包含更正的代码。给你:
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 :)好运
a = input() //for string
b = int(input()) //for int
c = float(input()) //for float
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
内进行串联