简体   繁体   English

Python - 我的程序出错

[英]Python - Error in my program

So I'm writing a python program that either sets the alarm off or doesn't, but can't seem to find my mistake for R1.所以我正在编写一个 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类型错误:“int”对象不可调用

Python interprets parens next to an object as "try to call this object". Python 将对象旁边的括号解释为“尝试调用此对象”。 If you want to multiply two things together, you need to explicitly tell python to multiply.如果你想把两个东西相乘,你需要明确地告诉python要相乘。

So it should be:所以应该是:

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

(added asterisk between 3583 and ((1/T)-(1/40)) ) (在3583((1/T)-(1/40))之间添加星号)

Edit: Right, that number is too large for float编辑:是的,这个数字对于float来说太大了

Using decimal to deal with that:使用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")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM