Python - 我的程序出错

时间:2015-06-27 18:16:17

标签: python python-3.4

所以我正在编写一个python程序,可以关闭或不关闭警报,但似乎无法找到我的错误。

T = float(input("What is the temperature in F?"))

from math import *

e=2.71828182845904523536028747135266249775724709369995

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

P1 = ((156300/R1) + 156,300)

P2 = ((156300/312600))

if P1 < P2:

    #print("The alarm will be sound")

else:

    #print("The alarm will not be sound")


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

TypeError:'int'对象不可调用

1 个答案:

答案 0 :(得分:1)

Python将对象旁边的parens解释为“尝试调用此对象”。如果你想将两个东西相乘,你需要明确告诉python乘以。

所以它应该是:

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

(在3583((1/T)-(1/40))之间添加了星号)

编辑:是的,这个数字对于float来说太大了

使用decimal处理:

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")