'TypeError: unsupported operand type(s) for %: 'NoneType' and 'float'

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)

The inlet conditions to compressor are 1atm pressure & 300K What is the final compression pressure? 20 What is the final compression temperature? 300 From graph, enthalpy at point 2 is 432 From graph, entropy at point 2 is 2.74

Yield= %f Traceback (most recent call last): File "", line 19, in print("Yield= %f") %(y) TypeError: unsupported operand type(s) for %: 'NoneType' and 'float'



Solution 1:[1]

You should be applying % formatting on the string but currently you are applying it on None (value returned by print function). In order to make your code work, you should be doing:

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

instead of:

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1