A) Create a function called To_Celsius that takes in a temperature in Fahrenheit temperature and returns the equivalent in Celsius.
B) Create another function called To_Fahrenheit that takes in a temperature in Celsius and returns the equivalent in Fahrenheit.
C) Use these functions to write a function called Print_EQ_Temps that prints out the Fahrenheit equivalents of all Celsius temperatures from 0°-100°, and the Celsius equivalents of all Fahrenheit temperatures from 32°-212°. Then, call this function in your program.
Hint: Use for loops to input into your functions.
def to_celsius(fahrenheit):
return 5 * (fahrenheit - 32) / 9
def to_fahrenheit(celsius):
return 9 * celsius / 5 + 32
def print_eq_temps():
for i in range(1, 101):
print(str(i) + "C\u00b0 = "
+ str(to_fahrenheit(i)) + "F\u00b0")
print("\n")
for i in range(32, 213):
print(str(i) + "F\u00b0 = "
+ str(round(to_celsius(i), 1)) + "C\u00b0")
print_eq_temps()
Comments
Leave a comment