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))
You were about 80% there.
Try the following code:
prices = ['31', '32']
for i in prices:
print(f"For only {int(i):.2f} dollars!")
For only 31.00 dollars!
For only 32.00 dollars!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.