Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from math import pi
- print ("Write the input for degree as such 'rd'")
- print ("This is from radians to degrees\nYou may use kelvin(k), fahrenheit(f), and celcius(c) as well")
- # This function gets information from the user
- def inputs():
- unit = raw_input("What unit do we have and what are we converting to? > ")
- num = raw_input("How much of the unit is being converted? > ")
- # This checks to see if the input num is equal to a number
- # if not, return user to reinput a number
- try:
- num = int(num)
- UnitCon(unit, num)
- except ValueError:
- print ("Not a valid input, please input a number")
- inputs()
- def UnitCon(unit, num):
- # Celcius to Kelvin
- if unit == "ck" in unit:
- ck =(num + 273)
- #number to string, adding unit at end
- kelvinString = str(ck) + ' K'
- print kelvinString
- # Kelvin to Celcius
- if unit == "kc" in unit:
- kc = (num - 273)
- celciusString = str(kc) + ' C'
- print celciusString
- # Fahrenheit to Kelvin
- if unit == "fk" in unit:
- fk = (((num-32)*float(.56))+273)
- kelvinString = str(fk) + ' K'
- print kelvinString
- #Kelvin to Fahrenheit
- elif unit == "kf" in unit:
- kf = (((num - 32)*float(.56))+273)
- fahrenheitString = str(kf) + ' F'
- print fahrenheitString
- #celcius to fahrenheit
- elif unit == "cf" in unit:
- cf = float((num - 32) * float(.5556))
- celciusString = str(cf) + ' C'
- print celciusString
- # fahrenheit to celcius
- elif unit == "fc" in unit:
- fc = float((num - 32)*float(.56))
- celciusString = str(fc) + ' C'
- print celciusString
- # radians to degrees
- elif unit == "rd" in unit:
- rd = float((num)*float(180/pi))
- degreeString = str(rd) + ' degrees'
- print degreeString
- # degrees to radians
- elif unit == "dr" in unit:
- dr = float((num)*float(pi/180))
- radianString = str(dr) + ' radians'
- print radianString
- else:
- print "Your input is invalid.\nPlease input a valid unit."
- inputs()
- # starts program
- inputs()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement