-1

my code:

temperature_f = input('Please enter the temperature :')
print('The temperature is' , 1.8 / (temperature_f - 32) ,'centigrade')

run code:

Please enter the temperature :50
Traceback (most recent call last):
  File "c:\Users\Aryan\.vscode\py\test1.py", line 2, in <module>
    print('The temperature is' , 1.8 / (temperature_f - 32) ,'centigrade')
                                        ~~~~~~~~~~~~~~^~~~
TypeError: unsupported operand type(s) for -: 'str' and 'int'

How can I fix this error?

I want to write a code that will convert fahrenheit to celsius for me but i am getting this error Please tell me how I can fix this error

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
aryan
  • 1
  • 2
    Does this answer your question? [How can I read inputs as numbers?](https://stackoverflow.com/questions/20449427/how-can-i-read-inputs-as-numbers) – jonrsharpe Dec 03 '22 at 19:29

2 Answers2

1

You have to type cast your input

temperature_f = input(int('Please enter the temperature :'))
0

type cast temperature string into float.

temperature_f = float(input('Please enter the temperature :'))
print('The temperature is' , 1.8 / (temperature_f - 32) ,'centigrade')
codester_09
  • 5,622
  • 2
  • 5
  • 27