Python Forum

Full Version: Small help with formatting
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Does anyone know how to make this all appear in one sentence?

print "You need to save £{0:.2f} each month.".format(finance)
print "To reach the target of £{0:.2f}.".format(cost)
I tried this but it just gives the same value in both positions.

print "You need to save £{0:.2f} each month to reach the target of £{0:.2f}".format(finance,cost)
I'm pulling my hair out. Well, what's left of it. Smile

I found it. Thanks anyway.

I found it. Thanks anyway. The first number controls the position.
You should also stop using Python 2 and switch to Python 3.
The can use cooler stuff like f-string Cool
>>> cost = 99.75999
>>> finance = 50000
>>> print(f"You need to save £{cost:.2f} each month to reach the target of £{finance:.2f}")
You need to save £99.76 each month to reach the target of £50000.00