djmurps
djmurps

Reputation: 21

TypeError: 'int' object is not callable? I can't seem to fix this error

I have tried rewriting my code multiple times, but I keep getting an error on line 16. Here is my code:

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

Upvotes: 0

Views: 90

Answers (2)

Akshat Harit
Akshat Harit

Reputation: 834

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

instead of

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

should fix it

EDIT: If you are using python 2.7, instead of 5/9, it should be 5.0/9 to force float results.

Upvotes: 2

tdelaney
tdelaney

Reputation: 77407

The problem is at 9(fahrenheit - 32). Python sees this as a function call, not multiplication. Operators must always be written explicitly.

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

Upvotes: 0

Related Questions