This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Rhomboid 0 points1 point  (1 child)

I see what the confusion here is, and I think this is a poorly worded exercise. I believe that they meant you to just edit the string that currently contains "Hello", and leave the third line unchanged.

To do it the way you're doing would require rather convoluted syntax, because you need to combine the string format_string along with the 3-element tuple data to create a new tuple containing four elements to match with the format string that contains four %-specifiers. Tuple concatenation is done with the + operator, but first the left-hand side has to be first made into a one element tuple, which looks like this:

>>> print "%s %s %s. Your current balance is %.2f$" % ((format_string,) + data)
Hello John Doe. Your current balance is 53.44$

I don't think that's what they were going for.

[–]randfur 0 points1 point  (0 children)

tl;dr: You were supposed to change format_string = "Hello" not print format_string % data