Rubykuby

Celsius to Fahrenheit

Sep 9th, 2013
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.64 KB | None | 0 0
  1. def isFloating(x):
  2.     try:
  3.         float(x) #Test if the inserted value is a floating point number (a number such as 3.14 or 1(.0))
  4.         return True
  5.     except:
  6.         return False #If the float(x) thing didn't work, it'll return False.
  7.  
  8. celsius = "" #Create a blank string value for celsius.
  9.  
  10. while not isFloating(celsius): #So long is celsius is not a floating point number, it'll loop this forever
  11.     celsius = input("Insert the temperature in degrees Celsius: ") #User input
  12.  
  13. fahrenheit = float(celsius) * 1.8 + 32 #Implementation of formula: F = C * 1.8 + 32
  14. print("It is " + str(fahrenheit) + " degrees Fahrenheit.") #Print the results
Advertisement
Add Comment
Please, Sign In to add comment