Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- conversions = {
- 'Celsius': (1, 0),
- 'Farenheit': (1.8, 32),
- 'Kelvin': (1, 273.15)
- }
- def convert_temp(temp, from_unit, to_unit):
- try:
- divide, subtract = conversions[from_unit]
- multiply, add = conversions[to_unit]
- except KeyError:
- raise KeyError('Unknown unit %s, %s' % from_unit, to_unit)
- return (temp - subtract) * multiply / divide + add
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement