我有一个要编辑/写入所选TXT文件的DEF函数

发布于 2025-02-11 22:38:21 字数 767 浏览 1 评论 0原文

我正在制作一个自动化的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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

咋地 2025-02-18 22:38:21

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 because write doesn't need that "a", that is the open's job.

影子是时光的心 2025-02-18 22:38:21

根据错误消息更正最后一行。 “ a”有剩余。

edit_quiz_file.write(multiple_choice_question)

另外,打开这样的文件要安全得多:

with open('mathquiz.txt', 'w') as file:
    file.write(multiple_choice_question)

Correct the last line as per the error message. The "a" there is surplus.

edit_quiz_file.write(multiple_choice_question)

Also, it is much safer to open the file like this:

with open('mathquiz.txt', 'w') as file:
    file.write(multiple_choice_question)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文