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:
# 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")
Leave a Reply