0
prices = ['31', '32']
txt = "For only {price:.2f} dollars!"
for i in prices:
    print(txt.format(prices))

Im trying this to get : For only 31.00 dollars For only 32.00 dollars but am facing this issue. Please help, Im a noob

prices = ['31', '32']
txt = "For only {price:.2f} dollars!"
for i in prices:
    print(txt.format(prices))
  • [Here is a example of formating](https://stackoverflow.com/a/455634/5990202). In your example `price` is unknown command/variable to python – Tomas Trdla Dec 09 '22 at 14:13

1 Answers1

0

You were about 80% there.
Try the following code:

Code:

prices = ['31', '32']

for i in prices:
    print(f"For only {int(i):.2f} dollars!")

Output:

For only 31.00 dollars!
For only 32.00 dollars!
ScottC
  • 3,941
  • 1
  • 6
  • 20