我有一个要编辑/写入所选TXT文件的DEF函数
我正在制作一个自动化的Python测验创建者,它将与测验一起组织和打印一个TXT文件,但是当我调用DEF create_multiple_choice时,它写下了老师想在下面询问的所有多项选择选项的问题,拒绝打印。
我得到的错误我得到
dit_quiz_file.write(多_choice_question,“ a”) TypeError:write()完全参数(2给定)
def create_multiple_choice():
global edit_quiz_file
multiple_choice_question = input("What would you like the question to be?")
print("write the multiple choice options below\n")
multiple_choice1 = input("What is the first option?")
multiple_choice2 = input("What is the second option?")
multiple_choice3 = input("What is the third option?")
multiple_choice4 = input("What is the fourth option?")
edit_quiz_file = open("mathquiz.txt", "a")
edit_quiz_file.write(multiple_choice_question, "a")
I am making an automated python quiz creator that will organize and print out a txt file with the quiz but when I call the def create_multiple_choice where it writes the question the teacher would like to ask with all the multiple choice options below it refuses to print.
the error I get
dit_quiz_file.write(multiple_choice_question, "a")
TypeError: write() takes exactly one argument (2 given)
def create_multiple_choice():
global edit_quiz_file
multiple_choice_question = input("What would you like the question to be?")
print("write the multiple choice options below\n")
multiple_choice1 = input("What is the first option?")
multiple_choice2 = input("What is the second option?")
multiple_choice3 = input("What is the third option?")
multiple_choice4 = input("What is the fourth option?")
edit_quiz_file = open("mathquiz.txt", "a")
edit_quiz_file.write(multiple_choice_question, "a")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
edit_quiz_file.write(protival_choice_question,“ a”)
是您的问题,它支持1个参数和2个参数,这是因为write> write
不需要该'一个“
,那就是Open
的作业。edit_quiz_file.write(multiple_choice_question, "a")
is your problem, it support 1 argument and 2 were given, this is becausewrite
doesn't need that"a"
, that is theopen
's job.根据错误消息更正最后一行。
“ a”
有剩余。另外,打开这样的文件要安全得多:
Correct the last line as per the error message. The
"a"
there is surplus.Also, it is much safer to open the file like this: