def temperature_converter(temp: float, conversion='both') -> float: celsius = round((temp - 32) * (5 / 9), 2) fahrenheit = round((temp * 9/5) + 32, 2) conversions = { 'celsius' : celsius, 'fahrenheit' : fahrenheit, 'both' : f"{celsius}c, {fahrenheit}f" } return conversions[conversion]
- def temperature_converter(temp: float, conversion='both') -> float:
convert = {'celsius' : (celsius := round((temp - 32) * (5 / 9) , 2)),'fahrenheit' : (fahrenheit := round((temp * 9 / 5) + 32, 2)),'both' : f"{celsius}c, {fahrenheit}f"- celsius = round((temp - 32) * (5 / 9), 2)
- fahrenheit = round((temp * 9/5) + 32, 2)
- conversions = {
- 'celsius' : celsius,
- 'fahrenheit' : fahrenheit,
- 'both' : f"{celsius}c, {fahrenheit}f"
- }
return convert[conversion]- return conversions[conversion]