From 09aa6fe4b3c7e6e23f27d0c58c39e102da6cb089 Mon Sep 17 00:00:00 2001 From: Talibuddin4577 Date: Sat, 19 Oct 2024 15:36:57 +0530 Subject: [PATCH] Update temperature_converter.py error is identified --- temperature_converter.py | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/temperature_converter.py b/temperature_converter.py index dfdde69..1318e96 100644 --- a/temperature_converter.py +++ b/temperature_converter.py @@ -1,11 +1,37 @@ -# temperature_converter.py def celsius_to_fahrenheit(c): return (c * 9/5) + 32 def fahrenheit_to_celsius(f): return (f - 32) * 5/9 +def celsius_to_kelvin(c): + return c + 273.15 + +def kelvin_to_celsius(k): + return k - 273.15 + +def fahrenheit_to_kelvin(f): + c = fahrenheit_to_celsius(f) + return celsius_to_kelvin(c) + +def kelvin_to_fahrenheit(k): + c = kelvin_to_celsius(k) + return celsius_to_fahrenheit(c) + if __name__ == "__main__": - temp = float(input("Enter temperature: ")) - print(f"{temp}°C is {celsius_to_fahrenheit(temp)}°F") - print(f"{temp}°F is {fahrenheit_to_celsius(temp)}°C") + print("Temperature Converter") + print("Choose the conversion type:") + print("1. Celsius to Fahrenheit") + print("2. Fahrenheit to Celsius") + print("3. Celsius to Kelvin") + print("4. Kelvin to Celsius") + print("5. Fahrenheit to Kelvin") + print("6. Kelvin to Fahrenheit") + + choice = input("Enter your choice (1-6): ") + + if choice in {'1', '2', '3', '4', '5', '6'}: + temp = float(input("Enter the temperature: ")) + + if choice == '1': + print(f"{te