fork download
  1. PI = 3.14159265358793
  2. inputs = ['3.1416rd', '90dr', '212fc', '70cf', '100cr', '315.15kc']
  3.  
  4. def dr(degrees):
  5. return degrees * (PI / 180)
  6.  
  7. def rd(radians):
  8. return radians * (180 / PI)
  9.  
  10. def fc(fahrenheit):
  11. return (fahrenheit - 32) * (5 / 9)
  12.  
  13. def fk(fahrenheit):
  14. return fc(fahrenheit) + 273.15
  15.  
  16. def cf(celsius):
  17. return celsius * (9 / 5) + 32
  18.  
  19. def ck(celsius):
  20. return celsius + 273.15
  21.  
  22. def kf(kelvin):
  23. return cf(kc(kelvin))
  24.  
  25. def kc(kelvin):
  26. return kelvin - 273.15
  27.  
  28. conversions = {
  29. 'dr': dr,
  30. 'rd': rd,
  31. 'fc': fc,
  32. 'fk': fk,
  33. 'cf': cf,
  34. 'ck': ck,
  35. 'kf': kf,
  36. 'kc': kc
  37. }
  38.  
  39. def convert(input_string):
  40. function = input_string[-2:]
  41. if function in conversions:
  42. amount = input_string[:-2]
  43. converted_to = input_string[-1:]
  44. return '{:.2f}{}'.format(conversions[function](float(amount)), converted_to)
  45. else:
  46. return 'No candidate for conversion.'
  47.  
  48. def main():
  49. for input_string in inputs:
  50. print(convert(input_string))
  51.  
  52. main()
  53.  
Success #stdin #stdout 0.03s 9984KB
stdin
Standard input is empty
stdout
180.00d
1.57r
100.00c
158.00f
No candidate for conversion.
42.00c