我正在编写一个执行以下操作的程序:
我编写了以下程序
import math
C = 50.0
H = 30.0
Q = []
D = input("Please input the D-Values\n").split(",")
[float(k) for k in D]
#[int(k) for k in D]
print("D = {}".format(D))
for i in D:
j = (math.sqrt((2*C*float(i))/H))
Q.append(j)
print("The answers are")
print(Q)
print(type(Q[0]))
print("Q = {:.2f}".format(Q))
Run Code Online (Sandbox Code Playgroud)
我在执行这个程序时遇到以下错误
Traceback (most recent call last):
File "/home/abrar/pythonPrograms/Challange6.py", line 24, in <module>
print("Q = {:.2f}".format(Q))
TypeError: non-empty format string passed to object.__format__
Run Code Online (Sandbox Code Playgroud)
我试图寻找这个问题的解决方案,但找不到答案。如果不包含 {:.2f},即使用 {},程序运行良好。但是,输出看起来非常混乱。
任何帮助都受到高度赞赏。