我想知道如何才能完成这项工作

时间:2016-11-14 14:24:17

标签: python

name = raw_input("Hello sir! What is your name?")
print ("Nice to meet you " + name + "! Where were you born?")
born = input(" ")
print ("So your name is " + name + " and you were born in " + born + "!")
  

我得到错误"很高兴见到你Will!你在哪里出世?        佛罗里达       Traceback(最近一次调用最后一次):       File" C:/Users/39.cr/PycharmProjects/untitled/test.py" ;,第3行,在       出生=输入("")       文件"",第1行,in       NameError:name' Florida'未定义"

2 个答案:

答案 0 :(得分:0)

您需要使用raw_input('')来获取出生地名,因为您使用的是Python 2.在Python 3上,您的代码可以正常工作。原因是在Python 2中你需要使用raw_input()来获取字符串而不是其他对象类型。

答案 1 :(得分:0)

试试这个:

name = raw_input("Hello sir! What is your name?")
born = raw_input("Nice to meet you " + name + "! Where were you born?")
print("So your name is " + name + " and you were born in " + born + "!")