[Tutor] Times Tables Program that constantly tells you that you are wrong!
Peter Otten
__peter__ at web.de
Thu Aug 23 08:19:10 EDT 2018
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}"""
More information about the Tutor
mailing list