Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Small help with formatting
#1
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.
Reply
#2
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 
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020