如何在python中定义我对变量的输入

时间:2017-11-06 16:50:11

标签: python variables

我正在制作一个程序,要求用户提供他们的名字和姓氏。 然后将此数据保存到.txt文件中。 我知道编码是基本的,易于理解,但最近这段代码决定不起作用。

file1 = open("document.txt",'w')

firstname = input("What is your first name?")

secondname = input("what is you second name?")
file1 = open ('document.txt','w')
file1.write (firstname + secondname)

newfile.close()

I am given the following error when running this piece of code

1 个答案:

答案 0 :(得分:0)

您必须使用raw_input才能在Python 2中获取字符串。input正在评估用户输入,查看未定义的变量name