Check on input Python 3.5.2
Check on input Python 3.5.2
Could you try with the following code:
def inp():
try:
Fahr = float(raw_input(Insert temperature in Fahrenheit: ))
return Fahr
except Exception as e:
return e
Fahr = inp()
while True:
if could not convert in str(Fahr):
Fahr = inp()
else:
break
Celcius = ((Fahr) - 32) * 5/float(9)
print(Your input: + str(Fahr) + Fahrenheit )
print(This is equal to: + str(Celcius) + Celcius )
The following is the output:
>>> ================================ RESTART ================================
>>>
Insert temperature in Fahrenheit: hello
Insert temperature in Fahrenheit: !@
Insert temperature in Fahrenheit: ()()((
Insert temperature in Fahrenheit: 10.5
Your input: 10.5 Fahrenheit
This is equal to: -11.9444444444 Celcius
input()
function always return a string.
Convert to int
or float
first.