TypeError:“int”对象不可调用?我似乎无法解决这个问题

2024-05-14 06:39:44 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经多次尝试重写代码,但在第16行不断出现错误。这是我的密码:

choice = input("fc; cf; fk;?") if (choice == 'fc'): def fc(): fahrenheit = int(input("enter temp: ")) celsius = (fahrenheit - 32) / 1.8 print(celsius) fc() elif (choice == 'cf'): def cf(): celsius = int(input("enter temp: ")) fahrenheit = (celsius * 1.8) + 32 print(fahrenheit) cf() elif (choice == 'fk'): def fk(): fahrenheit = int(input("enter temp: ")) kelvin = 5/9(fahrenheit - 32) + 273 print(kelvin) fk()

Tags: 代码inputdeftempcfintfcprint
2条回答

问题出在9(fahrenheit - 32)。Python认为这是一个函数调用,而不是乘法。运算符必须始终显式编写。你知道吗

kelvin = 5/9 * (fahrenheit - 32) + 273
kelvin = (5/9)*(fahrenheit - 32) + 273

而不是

kelvin = 5/9(fahrenheit - 32) + 273

应该修好它

编辑:如果您使用的是python2.7,而不是5/9,那么它应该是5.0/9以强制浮点结果。你知道吗

相关问题 更多 >