A Python program that can convert a Fahrenheit temperature to Celsius, or vice versa. The program should use two custom functions, f_to_c and c_to_f, to perform the conversions.
Explanation:
The code is given below :
def c_to_f(tempCelsius):
tempFahrenheit = ((9/5)*tempCelsius) + 32;
print("\n %.3f Celsius is %.3f Fahrenheit \n" %(tempCelsius, tempFahrenheit));
def f_to_c(tempFahrenheit):
tempCelsius = (tempFahrenheit - 32) * (5/9);
return tempCelsius;
(Import modules)
import temps;
def main():
temperature = float(input("\n Enter a temperature: "));
scale = input("\n Was that input Fahrenheit or Celsius c/f? ");
if scale.lower() == 'c':
temps.c_to_f(temperature);
else:
tempCel = temps.f_to_c(temperature);
print("\n %.1f Fahrenheit equals %.3f Celsius \n" %(temperature, tempCel));
main();