Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- temperature = 0;
- skip = False
- while(1): #infinite loop until user types exit
- inp = input('Type a temperature in fahrenheit or celsius\n').lower() # get user input and set to lowercase
- if(inp == "exit"):
- exit();
- splitWord = []
- for i in range(len(inp)):
- if(inp[i] == ' '):
- splitWord = inp.split(" ") # split the string into (temperature, f/c)
- break;
- if(len(splitWord) > 1):
- try:
- float(splitWord[0])
- except ValueError:
- print ("Invalid temperature input use TEMPERATURE C/F")
- continue
- if (splitWord[1] == 'celsius'): #if user entered celsius convert to fahrenheit
- temperature = float(splitWord[0])*1.8 + 32
- print('The temperature in fahrenheit is : ', temperature)
- if(splitWord[1] == 'fahrenheit'): # if user entered fahrenheit convert to celsius
- temperature = ((float(splitWord[0]) - 32) * 5/9)
- print('The temperature in celsius is : ', temperature)
- else:
- print("Invalid input")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement