Challenge: Convert Temperatures
Now with the two exercises solved, let’s have a challenge. This one is called convert temperatures. Write a program called
temperature.py that defines two functions.
convert_cel_to_far(), which takes one
float parameter representing degrees Celsius and returns a
float representing the same temperature in degrees Fahrenheit using the following formula:
F = C * 9/5 + 32 You will find this formula also in the text below this video.
The second part of this challenge is to create a function,
convert_far_to_cel(), which takes one
float parameter representing degrees Fahrenheit and returns a
float representing the same temperature in degrees Celsius using the following formula:
C = (F - 32) * 5/9.
01:34 Then the program should prompt the user to enter a temperature in degrees Celsius, and then display the temperature converted to Fahrenheit. Third, it should display all converted temperatures rounded to two decimal places.
At the end of this challenge, you should have a Python file named
temperature.py, and when you execute it in the terminal, there should be a prompt asking the user to enter a temperature in Fahrenheit and then output the converted Celsius temperature.
02:05 And after that, prompt the user to enter a Celsius temperature and output the Fahrenheit to the terminal. And when you output those temperatures in the terminal, you should round them to two decimal places, because remember, the numbers should be floats.
02:29 So yeah, there is quite a bit to do, but it’s a challenge. So stop this video course. Take your time and tackle the challenge. And once you solve the challenge yourself, you can come back to this video course and see how I solve the challenge.
Become a Member to join the conversation.