Here are the formulas for converting F to C and C to F:
T(°F) = T(°C) × 1.8 + 32 (Farenheit = Celsius * 1.8 + 32)
T(°C) = (T(°F) – 32) / 1.8 (Celsius = (Farenheit – 32) / 1.8)
Note: 1.8 = 9/5
Create an algorithm that does the following:
Display the following menu to the user:
Enter your selected option:
- Convert Celsius to Farenheit
Convert Farenheit to Celsius
Use an if-statement to determine which value to get from the user, and which formula to use.
- Create a function for CelsiusToFarenheit and another function for FarenheitToCelsius
- Call the appropriate function according to the user’s selection.
- From each of the functions, ask the user for the temperature, and then display the converted temperature.
*If you CAN NOT install the Python Software for security reasons, choose one of the online compilers below. Type in the code and click Run or Execute to see your results.
Note: using “raw_input” might not work with some Online compiles, please use “input” instead of raw_input.
- Online Compilers:
- https://onecompiler.com/python (Links to an external site.)
- https://www.tutorialspoint.com/execute_python_online.php (Links to an external site.)
- https://paiza.io/en/projects/new?language=python (Links to an external site.)
Python Programs must include the following documentation at the top of the program (use comment lines):
Student’s full name and Period #
Date of assignment
Description of program
What to submit:
If you downloaded Python 2.7, submit your python program file with extension *.py (EX: convert.py).
If you were not able to install Python 2.7, submit a print screen image of your online compiler program code after you run it.
Resource Videos on converting temperatures using python
(This video only shows how to convert from Celsius to Fahrenheit, you must also convert Fahrenheit to celsius)