TypeError:%不支持的操作数类型:“NoneType”和“float”

2024-05-28 20:06:30 发布

您现在位置:Python中文网/ 问答频道 /正文

if 1:
T1=300
P1=1
h1=462
s1=4.42
hf=29
sf=0.42
print("The inlet conditions to compressor are 1atm pressure & 300K")
Wi=(T1*(s1-sf))-(h1-hf)
P2= input("What is the final compression pressure? ")
T2= input("What is the final compression temperature? ")
h2= float(input("From graph, enthalpy at point 2 is "))
s2= float(input("From graph, entropy at point 2 is "))
y= float((h1-h2)/(h1-hf))
W= float((T1*(s1-s2))-(h1-h2))
Wf= float(W/y)
FOM= float(Wi/Wf)
print("")
print("Yield= %f") %(y)
print("Work reqd per unit mass of gas compressed= %f KJ/kg") %(W)
print("Work reqd per unit mass of gas liquified= %f KJ/kg") %(Wf)
print("Figure of Merit= %f") %(FOM)

压缩机的入口条件为1atm压力&300K 最后的压缩压力是多少?20个 最终压缩温度是多少?300个 从图表上看,点2的焓是432 从图上看,点2的熵是2.74

收益率%f 回溯(最近一次呼叫时间): 文件“”,第19行,in 打印(“收益率%f”)%(y) TypeError:不支持%的操作数类型:“NoneType”和“float”


Tags: ofinputish2sffloath1what
2条回答

问题出在代码的最后4行。这些语句中的每个表达式都需要括号()。不能对print函数应用%,因为它返回None

最后4行代码应该是

print(("Yield= %f") % (y))
print(("Work reqd per unit mass of gas compressed= %f KJ/kg") %(W))
print(("Work reqd per unit mass of gas liquified= %f KJ/kg") %(Wf))
print(("Figure of Merit= %f") %(FOM)) 

您应该对字符串应用%格式,但当前正在对None(由print函数返回的值)应用该格式。为了使代码工作,您应该执行以下操作:

print("Yield= %f" % (y)) 
#                 ^ moved inside `(...)` of print

而不是:

print("Yield= %f") %(y)

相关问题 更多 >

    热门问题