Matthew Polack wrote:

> I'm working my way through some of the tips you provided and tried to use
> the code given....but am getting an error at Line 75 in my code re:  not
> enough arguments for format string
> 
> _
>     return self.func(*args)
>   File "Timespicture.py", line 75, in checkanswer
>     Your current score is: %f""" % answer,score
> TypeError: not enough arguments for format string

>     fail_str = """
>     Sorry, you got it wrong,
>     the correct answer was %d
>     Your current score is: %f""" % answer,score

Python reads 

some_str % arg1, arg2

as

(some_str % arg1), arg2

To make the above work you have to use parens:

fail_str = """
Sorry, you got it wrong,
the correct answer was %d
Your current score is: %f""" % (answer, score)

Another option is to use f-strings to sidestep the issue:

fail_str = f"""
Sorry, you got it wrong,
the correct answer was {answer}
Your current score is: {score}"""


_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to