[Tutor] Times Tables Program that constantly tells you that you are wrong!
Alan Gauld
alan.gauld at yahoo.co.uk
Thu Aug 23 08:05:36 EDT 2018
On 23/08/18 05:47, Matthew Polack wrote:
> Hi Alan,
>
> 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
Lets go back to basics with Python assignment.
In your example you have a format string as:
fail_str = """
Sorry, you got it wrong,
the correct answer was %d
Your current score is: %f"""
And you try to insert 2 values, answer and score.
Unfortunately Python sees it like this:
fail_string = someData, moreData
Where someData looks like fmtString % answer
and moreData looks like score.
The solution is to use parentheses to create
an explicit tuple to group both of your data
values together:
fail_str = """
Sorry, you got it wrong,
the correct answer was %d
Your current score is: %f""" % (answer,score)
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list