0

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")
Mark Tolonen
  • 166,664
  • 26
  • 169
  • 251
  • Welcome to stack overflow! Have you checked [the docs for file.write](https://docs.python.org/3/tutorial/inputoutput.html#methods-of-file-objects)? The error is telling you what the problem is: Write only takes one argument and you've passed in 2 – G. Anderson Jun 30 '22 at 18:13
  • Hey, look at this answer will solve you problem. [here](https://stackoverflow.com/a/4719562/17637655) Ciao! Have a great time in SO – Ameya Jun 30 '22 at 18:16
  • There's no such thing as a "def function" in Python. There's **functions**, and **function definitions**, though. `def` means "define", so when you use it like `def whatever():`, it's shorthand for "define a function called `whatever`". – Random Davis Jun 30 '22 at 18:26

2 Answers2

0

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)
AboAmmar
  • 5,439
  • 2
  • 13
  • 24
0

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.

Blazing Blast
  • 101
  • 11