Advertisement
Guest User

Untitled

a guest
Jun 27th, 2016
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.97 KB | None | 0 0
  1. from math import pi
  2.  
  3. print ("Write the input for degree as such 'rd'")
  4. print ("This is from radians to degrees\nYou may use kelvin(k), fahrenheit(f), and celcius(c) as well")
  5.  
  6. # This function gets information from the user
  7. def inputs():
  8.    
  9.     unit = raw_input("What unit do we have and what are we converting to? > ")
  10.    
  11.     num = raw_input("How much of the unit is being converted? > ")
  12.    
  13.     # This checks to see if the input num is equal to a number
  14.     # if not, return user to reinput a number
  15.     try:
  16.         num = int(num)
  17.         UnitCon(unit, num)
  18.     except ValueError:
  19.         print ("Not a valid input, please input a number")
  20.         inputs()
  21.  
  22. def UnitCon(unit, num):
  23.    
  24.     # Celcius to Kelvin
  25.    
  26.     if unit == "ck" in unit:
  27.         ck =(num + 273)
  28.         #number to string, adding unit at end
  29.         kelvinString = str(ck) + ' K'
  30.         print kelvinString
  31.        
  32.     # Kelvin to Celcius
  33.    
  34.     if unit == "kc" in unit:
  35.         kc = (num - 273)
  36.         celciusString = str(kc) + ' C'
  37.         print celciusString
  38.    
  39.     # Fahrenheit to Kelvin
  40.    
  41.     if unit == "fk" in unit:
  42.         fk = (((num-32)*float(.56))+273)
  43.         kelvinString = str(fk) + ' K'
  44.         print kelvinString
  45.        
  46.     #Kelvin to Fahrenheit
  47.    
  48.     elif unit == "kf" in unit:
  49.         kf = (((num - 32)*float(.56))+273)
  50.         fahrenheitString = str(kf) + ' F'
  51.         print fahrenheitString
  52.        
  53.    
  54.     #celcius to fahrenheit
  55.     elif unit == "cf" in unit:
  56.         cf = float((num - 32) * float(.5556))
  57.         celciusString = str(cf) + ' C'
  58.         print celciusString
  59.        
  60.     # fahrenheit to celcius
  61.    
  62.     elif unit == "fc" in unit:
  63.         fc = float((num - 32)*float(.56))
  64.         celciusString = str(fc) + ' C'
  65.         print celciusString
  66.    
  67.     # radians to degrees
  68.    
  69.     elif unit == "rd" in unit:
  70.         rd = float((num)*float(180/pi))
  71.         degreeString = str(rd) + ' degrees'
  72.         print degreeString
  73.    
  74.     # degrees to radians
  75.    
  76.     elif unit == "dr" in unit:
  77.         dr = float((num)*float(pi/180))
  78.         radianString = str(dr) + ' radians'
  79.         print radianString
  80.        
  81.     else:
  82.         print "Your input is invalid.\nPlease input a valid unit."
  83.         inputs()
  84.        
  85.    
  86. # starts program       
  87. inputs()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement