簡體   English   中英

我收到此錯誤:Traceback(最近調用最后一次):文件“./prog.py”,第 4 行,在<module>關鍵錯誤:“價格”</module>

[英]I'm getting this error : Traceback (most recent call last): File "./prog.py", line 4, in <module> KeyError: 'price'

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

我正在嘗試這樣做: 只需 31.00 美元 只需 32.00 美元,但我正面臨這個問題。 請幫忙,我是菜鳥

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

你在那里大約有 80%。
試試下面的代碼:

代碼:

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!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM