[Solved] Python – Error in my program


Python interprets parens next to an object as “try to call this object”. If you want to multiply two things together, you need to explicitly tell python to multiply.

So it should be:

R1 = ((33192)*e)**3583*((1/T)-(1/40))

(added asterisk between 3583 and ((1/T)-(1/40)))

Edit: Right, that number is too large for float

Using decimal to deal with that:

import decimal
#remove import math, that doesn't seem to be used anywhere?

e = decimal.Decimal('2.71828182845904523536028747135266249775724709369995')

T = decimal.Decimal(input("Temperature(F): "))

R1 = (33192*e)**3583*((1/T)-(1/decimal.Decimal(40)))

P1 = (156300/R1) + decimal.Decimal(156300) #removed comma here. That comma was making P1 a tuple

P2 = decimal.Decimal(156300)/decimal.Decimal(312600) #removed excess parens and coerced everything to decimal.Decimal

if P1 < P2:
    #print("The alarm will be sound")
else:
    #print("The alarm will not be sound")

6

solved Python – Error in my program