Python - 我的程序出错

Python - Error in my program

所以我正在编写一个 python 程序来关闭或不关闭闹钟,但似乎找不到我对 R1 的错误。

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' object is not callable

Python 将对象旁边的括号解释为 "try to call this object"。如果你想把两个东西相乘,你需要明确地告诉 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")