Program Listing
class TemperatureConverter:
@staticmethod
def celsius_to_fahrenheit(celsius):
return (celsius * 9 / 5) + 32
@staticmethod
def fahrenheit_to_celsius(fahrenheit):
return (fahrenheit - 32) * 5 / 9
celsius_temperature = 34.36
fahrenheit_temperature = 134.98
print("\n\tTemperature Converter Using a Class in Python\n")
print("\tCelsius to Fahrenheit: {:.2f}°C = {:.2f}°F".format(celsius_temperature, TemperatureConverter.celsius_to_fahrenheit(celsius_temperature)))
print("\tFahrenheit to Celsius: {:.2f}°F = {:.2f}°C".format(fahrenheit_temperature, TemperatureConverter.fahrenheit_to_celsius(fahrenheit_temperature)))
print("\n\tEnd of Program. Thank you for Using This Program\n")
No comments:
Post a Comment