我正在制作一个程序,要求用户提供他们的名字和姓氏。 然后将此数据保存到.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
答案 0 :(得分:0)
您必须使用raw_input
才能在Python 2中获取字符串。input
正在评估用户输入,查看未定义的变量name
。