python/temperature_conversion.py

22 lines
538 B
Python

#This program converts temperature from Fahrenheit to Celcius or Celcius to Fahrenheit depending on the input from the user
unit = input("Is this temperature in Celcius or Fahrenheit (C/F)?: ")
temp = float(input("Please enter a temperature: "))
if unit == "C":
temp = round((temp * 1.8)+32, 2)
print(f"The temperature in degrees F is {temp}F")
elif unit == "F":
temp = round((temp - 32) * 5 / 9, 2)
print(f"The temperature in degrees C is {temp}C")
else:
print(f"{unit} is an invalid unit of measurement.")