From fc88665bccd07a03f91220a73b4077e69b4c9252 Mon Sep 17 00:00:00 2001 From: alisezisli Date: Thu, 21 Oct 2021 10:54:26 +0300 Subject: [PATCH] Temperature converter Celsius - Fahrenheit converter in Python --- .../2-temperature-converter.py | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100755 Basic Programs/Python/Tricky Problems/2-temperature-converter.py diff --git a/Basic Programs/Python/Tricky Problems/2-temperature-converter.py b/Basic Programs/Python/Tricky Problems/2-temperature-converter.py new file mode 100755 index 0000000..c48847b --- /dev/null +++ b/Basic Programs/Python/Tricky Problems/2-temperature-converter.py @@ -0,0 +1,21 @@ +#! /usr/bin/python3 + +#Get the temperature from user: +temp = input("Input the temperature you like to convert (For example: 28C, 52F): ") +#Split the value: +degree = int(temp[:-1]) +i_convention = temp[-1] + +#Check whether temperature entered in Celsius: +if i_convention.upper() == "C": + result = int(round((9 * degree) / 5 + 32)) + o_convention = "Fahrenheit" +#Check whether temperature entered in Fahrenheit: +elif i_convention.upper() == "F": + result = int(round((degree - 32) * 5 / 9)) + o_convention = "Celsius" +else: + print("I don't get this. Sorry. Bye!") + quit() + +print("The temperature in", o_convention, "is", result, "degrees.")