Python beginner Diary Day 011: Temperature Conversion

Today’s lesson was about creating a temperature converter in Python using if-statements again. I use PyCharm. I follow Bro Code’s instructions from his Python course:

https://youtu.be/r3xaSDjoQA8
 # PYTHON temperature converter


unit = input("Is this temperature in Celsius or Fahrenheit? (C/F): ").upper()
temp = float(input("Enter the temperature: "))

if unit == "C":
    temp = round((9 * temp) / 5 + 32, 1)
    print(f"The temperature in Fahrenheit is: {temp} degrees Fahrenheit.")
elif unit == "F":
    temp = round((temp - 32) * 5 / 9, 1)
    print(f"The temperature in Celsius is: {temp} degrees Celsius.")
else:
    print(f"{unit} isn't a valid unit")

Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *