I am a beginner and it might feel like a silly question.
I am trying to create a simple program,a temperature converter from Celsius to F*.
Which takes:
- 'quit' for stopping program
- int values for providing the correct result
Problem: any text value entered by user is handled through try expect error and a while loop which ask them to enter the int value again, but the second time user enters a correct value (which is int) the system considers it as a string and the loop is never ending.
Here is my program:
# Program to convert Celsius to Fahrenheit
import time
while True:
userinput= input(" 1 Enter the temperature in celsius: "
"Enter Quit if you want to close the converter")
if userinput.lower()=='quit':
print('Closing the application. Thanks for using the converter')
break
try:
userinput= float(userinput)
except ValueError:
print('You cannot enter text, please use numbers')
while userinput.lower()!='quit':
if type(userinput)!=str:
userinput = float(userinput)
print(type(userinput))
break
else:
while type(userinput)==str:
userinput = (input(" 2. Oops Enter the temperature in celsius: "
"Enter Quit if you want to close the converter"))
print(type(userinput))
## my problem is here even if enter a integer 2 as userinput. i am getting the type userinput as str. Can someone help me
type(userinput)
userinput=float(userinput)
f=userinput*9.0/5+32
print('Your input was:',userinput,'\n'*2,'The corresponding Fareinheit is',f,'\n'*3, '---'*25)