Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a Python program that can convert a Fahrenheit temperature to Celsius, or

ID: 3848633 • Letter: W

Question

Write 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. Both of these functions should be defined in a custom module named temps. Custom function c_to_f should be a void function defined to take a Celsius temperature as a parameter. It should calculate and print the equivalent Fahrenheit temperature accurate to three decimal places. Custom function f_to_c should be a value-returning function defined to take a Fahrenheit temperature as a parameter. This function should calculate the equivalent Celsius temperature and return it. In the main function, your program should: prompt the user to enter a temperature (as a float type). indicate the temperature scale of the temperature just entered. call the appropriate function from the temps module. if the Celsius temperature is being determined, it should be displayed accurate to three decimal places. EXAMPLE OUTPUT 1 Enter a temperature 32 Was that input Fahrenheit or Celsius c/f? f 32.0 Fahrenheit equals 0.000 Celsius EXAMPLE OUTPUT 2 Enter a temperature 100 Was that input Fahrenheit or Celsius c/f? c 100.0 Celsius is 212.000 Fahrenheit

Please show code as wrote in the Python editor showing indentations as appropriate, thank you

Explanation / Answer


def c_to_f (): # function for converting from Celsius to Fahrenheit
deg_celsius = float(raw_input("How many degrees Celsisus is it outside?")) # get user to input Celsius temp
deg_fahrenheit = (deg_celsius * 1.8) + 32 # calculates Fahrenheit temp
print "It is", deg_fahrenheit, "degrees Fahrenheit outside." # prints converted temperature

def f_to_c (): # function for converting from Fahrenheit to Celsius
deg_fahrenheit = float(raw_input("How many degrees Fahrenheit is it outside?")) # get user to input Fahrenheit temp
deg_celsius = (deg_fahrenheit - 32) / 1.8 # calculates Celsius temp
print "It is", deg_celsius, "degrees Celsius outside." # prints converted temperature

type_conversion = raw_input("Type c_to_f to convert from Celsius to Fahrentheit Type f_to_c to convert from Fahrenheit to Celsius") # asks user which conversion they want

while (type_conversion != "c_to_f" and type_conversion != "f_to_c"): # displays if user puts in an invalid response
type_conversion = raw_input("Type c_to_f to convert from Celsisus to Fahrentheit Type f_to_c to convert from Fahrenheit to Celsius")

if (type_conversion == "c_to_f"):
c_to_f () # run C2F function

if (type_conversion == "f_to_c"):
f_to_c () # run F2C function

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote