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")
CodePudding user response:
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.
CodePudding user response:
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)