Build a Fahrenheit-to-Celsius Converter
Build a Python app that converts Fahrenheit input into Celsius.
Introduction
30 Second Summary
When a weather forecast uses a different temperature scale, a familiar number can suddenly feel meaningless. Converting it takes one formula, but a computer must first recognise the typed value as a number.
In this project, you will build an interactive Fahrenheit-to-Celsius terminal app with Python. You will watch a typed temperature change from a string into a floating-point number before your app calculates Celsius.
What You'll Build
You will run your converter in Visual Studio Code to turn a Fahrenheit temperature into a labeled Celsius weather report rounded to one decimal place.
By the end of this project, you'll have:
- Try different temperatures by entering whole numbers, decimals, or negative values in the terminal.
- Watch the type change from text to a floating-point number before the calculation runs.
- Read a clear weather report that shows the Fahrenheit value plus its Celsius equivalent rounded to one decimal place.
- Secret Mission: Catch nonnumeric input such as warm to show a friendly message without a traceback.
Are there any prerequisites?
You need a Mac with internet access plus administrator credentials to install Python 3.14.8.
You should already have Visual Studio Code installed.
Before We Start
Before any hands-on work begins, this is your moment to commit to the weather converter you are building. Clarifying what it accepts and why type conversion matters gives every later step a clear purpose.
Set Up Python in Visual Studio Code
Your weather converter needs a program that can execute its instructions. Visual Studio Code gives you the editor for writing them.
A Python interpreter runs the file. The Microsoft Python extension connects Visual Studio Code to that interpreter.
This step sets up Python 3.14.8 with the extension. A one-line starter file proves that your editor can run Python code.
In this step, get ready to:
- Install Python 3.14.8 and complete its certificate setup.
- Install the Microsoft Python extension and select the correct interpreter.
- Create the weather converter project and run its starter file.
Install Python 3.14.8
The interpreter turns the instructions in a .py file into a running program. Checking your current version reveals which installation path you need.
- Press Cmd+Space to open Spotlight.
- Type Visual Studio Code and press Enter to open it.
Visual Studio Code opens with its editor area ready.
- Select Terminal in the top menu bar.
- Select New Terminal to display the integrated terminal.
The integrated terminal appears at the bottom of Visual Studio Code.
- Check the Python version available on your Mac by running this command:
python3 --version
What does this command do?
The python3 command starts Python 3. The --version option asks it to display the installed version without opening the interpreter.
Choose the tab that matches the result in your terminal.
✔️ I see version 3.14.8
Your Mac already has the required Python version. Complete the certificate step so Python can make secure connections when future projects download packages.
- In Finder, navigate to /Applications/Python 3.14/.
- Double-click Install Certificates.command to run the certificate setup.
A temporary Terminal window completes the setup. You should see Successfully installed certifi followed by update complete.
ⓧ I see an older version
The installed version is below the project requirement. Installing Python 3.14.8 gives your converter the version used throughout this project.
The download plus installation can take a few minutes. A short pause during the installer is expected.
- Open the official Python release page for version 3.14.8.
- Select the macOS installer link in the files table.
- Open the downloaded .pkg file.
- Select Continue as the installer presents each setup screen.
- Select Agree to accept the software license.
- Select Install to begin the installation.
The administrator prompt is expected because the installer adds Python to your Mac.
- Enter your Mac administrator credentials when prompted.
- In Finder, navigate to /Applications/Python 3.14/ after the installer finishes.
- Double-click Install Certificates.command to complete the certificate setup.
A temporary Terminal window completes the setup. You should see Successfully installed certifi followed by update complete.
ⓧ Command not found
Python is ready to install. The official macOS package provides Python 3.14.8 plus the certificate script required for this setup.
The first installation can take a few minutes while your Mac copies the interpreter files. A quiet installer window during that time is normal.
- Open the official Python release page for version 3.14.8.
- Select the macOS installer link in the files table.
- Open the downloaded .pkg file.
- Select Continue as the installer presents each setup screen.
- Select Agree to accept the software license.
- Select Install to begin the installation.
The administrator prompt is expected because the installer adds Python to your Mac.
- Enter your Mac administrator credentials when prompted.
- In Finder, navigate to /Applications/Python 3.14/ after the installer finishes.
- Double-click Install Certificates.command to complete the certificate setup.
A temporary Terminal window completes the setup. You should see Successfully installed certifi followed by update complete.
That completes the Mac-level setup. Python can now run local files with its certificates in place.
Connect Visual Studio Code to Python
The Python extension adds language support plus the controls for running Python files. Selecting an interpreter tells the extension which Python installation your converter should use.
- Quit Visual Studio Code by pressing Cmd+Q.
Restarting the editor lets it detect the newly installed interpreter.
- Press Cmd+Space to open Spotlight.
- Type Visual Studio Code and press Enter to reopen it.
Visual Studio Code starts a fresh session that can detect Python 3.14.8.
- Select the Extensions icon in the Activity Bar.
- Enter Python in the extension search field.
The search results display available Python extensions.
- Select the extension named Python that is published by Microsoft.
- Click Install on the extension page.
The extension page shows that the Microsoft Python extension is installed.
- Press Command+Shift+P to open the Command Palette.
The Command Palette gives you access to commands added by the extension.
- Enter Python: Select Interpreter in the Command Palette.
- Select Python: Select Interpreter from the results.
Visual Studio Code displays the Python interpreters it found on your Mac.
- Select the interpreter labeled Python 3.14.8.
The selected interpreter now appears in the Visual Studio Code status area.
Interpreter missing from the list?
Confirm that the extension listing names Microsoft as the publisher. Restart Visual Studio Code once more if the interpreter list was open during installation.
If Python 3.14.8 still does not appear, repeat the certificate and installation checks from the previous substep.
Help me connect the Microsoft Python extension to Python 3.14.8 on my Mac.
Run the starter weather converter
The integrated terminal provides a direct check of the Python installation. Your first source file then proves that the editor can pass Python code to the selected interpreter.
- Select Terminal in the Visual Studio Code menu bar.
- Select New Terminal to start a fresh integrated terminal.
The fresh terminal appears at the bottom of the editor.
- Confirm the installed Python version by running this command:
python3 --version
What does this check prove?
This command asks the Python installation available to the terminal for its version. Matching the project version confirms that the interpreter is available from Visual Studio Code.
You should see Python 3.14.8 in the integrated terminal.
Still seeing the wrong version?
Close the current terminal with its trash can icon. Create a fresh terminal so it can detect the newly installed Python version.
Restart Visual Studio Code if the fresh terminal still reports an older version.
Help me fix the Python version shown by the Visual Studio Code integrated terminal.
A dedicated folder keeps the converter file easy to find. You will place the folder on your Desktop so its location stays clear throughout the project.
- Select File in the Visual Studio Code menu bar.
- Select Open Folder from the menu.
The macOS folder picker opens.
- Select Desktop in the folder picker.
- Select the new-folder control in the folder picker.
The folder picker displays a field for the new folder name.
- Enter weather-converter as the folder name.
Visual Studio Code may show a workspace trust prompt after opening the folder. This folder contains only the file you create in this project.
- Select Open to open the weather-converter folder.
- Confirm the workspace trust prompt if Visual Studio Code displays it.
The Explorer sidebar now shows the empty weather-converter folder.
- Click the New File icon in the Explorer sidebar.
- Enter temperature_converter.py as the file name.
The new temperature_converter.py file opens in the editor.
- Add the starter message to temperature_converter.py by entering this line:
print("Weather converter ready")
What does this code do?
- The print() function sends a message to the integrated terminal.
- The message proves that Visual Studio Code passed your file to the Python interpreter.
- Save temperature_converter.py by pressing Cmd+S.
Before you run the starter file, what message do you expect the integrated terminal to show?
- Select Run Python File using the play button in the top-right corner of the editor.
That first run is your proof. The integrated terminal displays Weather converter ready.
Starter message missing?
Confirm that temperature_converter.py is the active editor tab. Save the file before selecting Run Python File again.
Check that Python 3.14.8 remains selected as the interpreter if another version runs.
Help me find out why my Python starter message is missing from the Visual Studio Code terminal.
✔️ Awesome, I've got everything!
Your starter file is saved. The successful terminal message confirms that your Python setup works.
ⓧ I'd like to double check the full code
Compare your saved file with this complete starter version.
print("Weather converter ready")
What should match?
Your file should contain this single print() line. Matching the capitalization plus quotation marks ensures the terminal displays the expected message.
Your Python workspace is ready for the converter logic. Next, you will replace the starter message with an interactive temperature prompt.
Capture Temperature as Text
Your starter file already proves that Visual Studio Code can run Python code. The converter now needs a temperature that changes each time you run it.
In this step, you'll capture that response as text. You'll use type() to make its starting type visible before any calculation.
In this step, get ready to:
- Replace the fixed readiness message with an interactive temperature prompt.
- Display the entered Fahrenheit value with its Python type.
- Test decimal, whole-number, and negative temperatures.
Capture and inspect the temperature
The input() function pauses the program while it waits for your response. It returns your entry as a string.
- In the temperature_converter.py tab from earlier, select the existing print("Weather converter ready") line.
- Replace the selected line by pasting the code below:
fahrenheit_text = input("Enter temperature in Fahrenheit: ")
print("You entered:", fahrenheit_text)
print("Python stored it as:", type(fahrenheit_text))
What does this code do?
- The fahrenheit_text variable holds the characters entered at the prompt.
- The first print() displays the entered value beside a clear label.
- The type(fahrenheit_text) expression asks Python to reveal how it stored the response.
- Save temperature_converter.py by pressing Cmd+S (macOS) or Ctrl+S (Windows).
- Start the file by selecting Run Python File in the top-right corner of the editor.
- Enter 72.5 at the temperature prompt.
- Submit the temperature by pressing Enter.
You'll see You entered: 72.5. The next line ends with <class 'str'>.
That first interactive run is working. Your converter now accepts a temperature from the terminal.
Not seeing the prompt?
- Confirm temperature_converter.py is the active editor tab before selecting Run Python File.
- Confirm Python 3.14.8 remains selected in the Visual Studio Code status bar.
- Ask for help if the file runs without displaying the prompt: help me troubleshoot why my Python input prompt does not appear in the Visual Studio Code terminal.
✔️ Awesome, I've got everything!
Your temperature_converter.py file now captures the response and displays its type.
ⓧ I'd like to double check the full code
fahrenheit_text = input("Enter temperature in Fahrenheit: ")
print("You entered:", fahrenheit_text)
print("Python stored it as:", type(fahrenheit_text))
Test different temperature shapes
A decimal point or minus sign changes the characters in the response. The input() function still returns that response as text.
Before you run the next checks, do you expect 32 and -4 to have the same type as 72.5?
- Start another test by selecting Run Python File.
- Enter 32 at the temperature prompt.
- Submit the temperature by pressing Enter.
You'll again see <class 'str'> after the entered value.
- Start the final test by selecting Run Python File.
- Enter -4 at the temperature prompt.
- Submit the temperature by pressing Enter.
You'll see -4 followed by <class 'str'>. This confirms that each numeric-looking response is still stored as text.
You have now proved the key idea: the converter needs float() before it can use the temperature in arithmetic.
Your converter now captures changing weather data and reveals its starting type. Next, you'll test whether that text can take part in the temperature formula.
Expose the Type Error
Your converter in Visual Studio Code can now capture a Fahrenheit value through input(). The type check proves that Python stores the value as text.
A temperature that looks numeric cannot take part in subtraction while it remains text. This step deliberately attempts the calculation so you can observe what Python does.
In this step, get ready to:
- Add the Celsius formula before converting the entered text.
- Run the converter with 72 to reveal the type mismatch.
- Connect the TypeError to the earlier <class 'str'> output.
Add the failing calculation
The Fahrenheit-to-Celsius formula is (°F - 32) / 1.8. Your program currently holds the entered Fahrenheit value in fahrenheit_text.
You will use that stored value directly in the formula. This exposes what arithmetic requires from its inputs.
- In the open temperature_converter.py tab, place your cursor after print("Python stored it as:", type(fahrenheit_text)).
- Press Enter twice to leave one blank line.
- Append the attempted calculation by copying this code:
celsius = (fahrenheit_text - 32) / 1.8
print("Celsius:", celsius)
What does this code do?
- The first line asks Python to apply the temperature formula to the value stored in fahrenheit_text.
- The second line asks Python to print the value assigned to celsius after the calculation completes.
- Save temperature_converter.py.
Run the deliberate mismatch
Before you run the converter, do you think Python will reach the line that prints celsius?
- Select Run Python File in the top-right corner of Visual Studio Code.
- Enter 72 at the terminal prompt.
You will see You entered: 72 followed by Python stored it as: <class 'str'>. The program stops on the celsius assignment.
The final line of the traceback names TypeError. No Celsius result is printed.
That deliberate failure is useful. You have proved that Python cannot use the stored text in this subtraction.
Not seeing the TypeError?
- Confirm that the calculation uses fahrenheit_text exactly.
- Save temperature_converter.py if the terminal only shows the earlier type output.
- Select Run Python File again after saving the file.
Help me find why my converter does not show the expected TypeError.
Connect the error to the stored type
A traceback identifies where execution stopped. Its final line names the exception that ended the program.
- Read the final line of the traceback in the integrated terminal.
- Compare its reference to str with the earlier <class 'str'> output.
- Leave the failing celsius calculation unchanged in temperature_converter.py.
Why does the subtraction stop?
Subtraction needs numeric operands. fahrenheit_text is a str. The value 32 is an int.
Python raises TypeError when an operation receives an inappropriate type. Execution ends before Python reaches the final print() call.
✔️ Awesome, I've got everything!
Your saved file contains the original type check plus the deliberate failing calculation.
ⓧ I'd like to double check the full code
fahrenheit_text = input("Enter temperature in Fahrenheit: ")
print("You entered:", fahrenheit_text)
print("Python stored it as:", type(fahrenheit_text))
celsius = (fahrenheit_text - 32) / 1.8
print("Celsius:", celsius)
This version preserves the text input. It adds the failing arithmetic exactly where the traceback points.
Before you run it one last time, which line do you expect Python to stop on?
- Select Run Python File in the top-right corner of Visual Studio Code.
- Enter 72 at the terminal prompt.
You will again see <class 'str'> before execution stops on the subtraction line. The final traceback line names TypeError instead of showing a Celsius result.
You have exposed the exact type mismatch blocking the converter. Next, you will turn the entered text into a number so the formula can run.
Convert Text and Calculate Celsius
Your previous run proved that input() stores 72 as a string. The converter stopped because the formula tried to subtract 32 from that text.
In this step, you will use Python's float() function to create a floating-point number from the entered text. The formula can then calculate Celsius for whole-number, decimal, or negative temperatures.
In this step, get ready to:
- Convert the string returned by input() into a floating-point number.
- Compare the original type with the converted type.
- Calculate Celsius with whole-number and negative test values.
Convert the entered text
The float() function reads a numeric string such as 68 or -4. It returns a number that supports arithmetic.
You will store that number in fahrenheit. Keeping fahrenheit_text lets you compare the value before conversion with the value after conversion.
- In temperature_converter.py, locate the final two lines beginning with celsius = (fahrenheit_text - 32) / 1.8.
- Select both final lines.
- Replace the selected lines with the code below:
fahrenheit = float(fahrenheit_text)
print("After conversion:", type(fahrenheit))
celsius = (fahrenheit - 32) / 1.8
print("Celsius:", celsius)
What Does This Code Do?
- The float(fahrenheit_text) call converts the entered text into a floating-point number.
- The fahrenheit variable stores the converted number.
- The second type() call reveals the converted value's type.
- The Celsius formula uses fahrenheit because that value supports subtraction and division.
- Save temperature_converter.py.
Before you run the converter, which two types do you expect it to display for the original value and the converted value?
- Select Run Python File from the top-right corner of the editor.
- Enter 68 in the integrated terminal.
You'll see <class 'str'> for the original value. You'll see <class 'float'> after conversion.
The final line reads Celsius: 20.0. You have closed the exact type gap that stopped the previous version.
Still Seeing the Subtraction Failure?
- Check that the formula uses fahrenheit in place of fahrenheit_text.
- Check that fahrenheit = float(fahrenheit_text) appears above the Celsius formula.
- Save temperature_converter.py before running it again.
Help me compare my converter with the working version.
✔️ Awesome, I've got everything!
Your saved file now converts Fahrenheit text before using it in the Celsius formula.
ⓧ I'd like to double check the full code
fahrenheit_text = input("Enter temperature in Fahrenheit: ")
print("You entered:", fahrenheit_text)
print("Python stored it as:", type(fahrenheit_text))
fahrenheit = float(fahrenheit_text)
print("After conversion:", type(fahrenheit))
celsius = (fahrenheit - 32) / 1.8
print("Celsius:", celsius)
This complete file preserves the original text for comparison. It uses the converted number for the calculation.
Test more weather temperatures
Numeric strings can represent freezing temperatures or values below zero. Testing both confirms that float() preserves the range your weather converter needs.
- Select Run Python File again.
- Enter 32 in the integrated terminal.
You'll see <class 'float'> after conversion. The final line reads Celsius: 0.0.
- Select Run Python File once more.
- Enter -4 in the integrated terminal.
You'll see the converted type again. The final line reads Celsius: -20.0.
Verify the finished calculation
This final check proves that the original text remains visible while the converted value completes the formula.
Before this final run, what type and Celsius result do you expect after entering 68?
- Select Run Python File from the top-right corner of the editor.
- Enter 68 in the integrated terminal.
You'll see <class 'str'> before conversion. You'll see <class 'float'> after conversion.
The terminal finishes with Celsius: 20.0. Your converter now accepts text and calculates with a floating-point number.
Your converter now calculates accurate Celsius values from entered text. Next, you'll turn the raw result into a one-decimal weather report.
Format the Weather Report
Your converter already calculates Celsius correctly. Its raw output leaves key weather context out.
In this step, you will round the Celsius result to one decimal place. You will use an f-string to label both temperatures with their units.
In this step, get ready to:
- Round the Celsius result to one decimal place.
- Format the Fahrenheit value and Celsius value with their units.
- Verify the finished report with four different temperatures.
Round and label the result
The round() function controls the number of decimal places in a result. An f-string places calculated values directly inside a readable sentence.
- Switch back to temperature_converter.py in the editor.
- Find the celsius = (fahrenheit - 32) / 1.8 line near the bottom of the file.
- Replace the final two lines with this code:
celsius = (fahrenheit - 32) / 1.8
rounded_celsius = round(celsius, 1)
print(f"{fahrenheit}°F is {rounded_celsius}°C")
What does this formatting code do?
- The round(celsius, 1) call rounds the Celsius result to one decimal place.
- The f prefix lets Python evaluate the expressions inside the braces.
- The degree symbols label each value with its temperature unit.
- Save temperature_converter.py.
- Select Run Python File in the top-right corner of the editor.
- Enter 32 when the terminal prompts for a temperature.
You will see 32.0°F is 0.0°C on the final line. Both temperatures now carry clear units.
Report still looks raw?
- Confirm that rounded_celsius is spelled the same way on both new lines.
- Confirm that the original raw Celsius print line has been replaced.
Help me fix the formatting in my Python temperature converter.
The finished file keeps the type conversion visible. Its final section turns the calculation into a weather report.
✔️ Awesome, I've got everything!
Your formatting code is complete.
ⓧ I'd like to double check the full code
fahrenheit_text = input("Enter temperature in Fahrenheit: ")
print("You entered:", fahrenheit_text)
print("Python stored it as:", type(fahrenheit_text))
fahrenheit = float(fahrenheit_text)
print("After conversion:", type(fahrenheit))
celsius = (fahrenheit - 32) / 1.8
rounded_celsius = round(celsius, 1)
print(f"{fahrenheit}°F is {rounded_celsius}°C")
How is the finished file organized?
- The first section captures the original text for the initial type check.
- The middle section converts that text into a floating-point number for the formula.
- The final section rounds the result before the f-string builds the report.
Test the finished report
A useful converter needs consistent output across whole numbers and decimal values. It also needs to handle temperatures below zero.
- Select Run Python File.
- Enter 68 at the prompt.
You will see 68.0°F is 20.0°C on the final line.
- Select Run Python File again.
- Enter -40 at the prompt.
You will see -40.0°F is -40.0°C on the final line.
Before the final run, what do you expect the report to show for a Fahrenheit value of 98.6?
- Select Run Python File one more time.
- Enter 98.6 at the prompt.
You will see 98.6°F is 37.0°C on the final line. You now have a consistent weather report for every test value.
Final value does not match?
- Confirm that the conversion formula still reads (fahrenheit - 32) / 1.8.
- Confirm that the second argument passed to round() is 1.
Help me find why my Fahrenheit-to-Celsius report has the wrong result.
Secret mission
Keep the Converter from Crashing
A single word such as warm currently stops your converter with a traceback. Add targeted exception handling so invalid input receives a friendly correction while valid temperatures still convert normally.
Clean Up Your Resources
Clean Up Your Resources
Your local weather converter creates no ongoing charges. Choose whether to keep the project available, pause your work, or delete the folder.
Resources you used:
- The weather-converter project folder containing temperature_converter.py.
Keep everything running
Keeping your setup preserves the finished converter for future practice. Everything stays local at no cost.
- Leave the weather-converter folder in place.
- Keep Python 3.14.8 installed for future scripts.
- Keep the Microsoft Python extension available in Visual Studio Code.
- Return to temperature_converter.py when you want to test more temperatures.
Pause - I'll come back to this later
A paused local project uses no cloud resources. Its saved file remains ready for your next practice session.
- Close Visual Studio Code.
- Leave the weather-converter folder on your Mac.
Delete - I don't want to use this again
Deleting the folder permanently removes your finished converter. Your Python installation stays available for future projects.
- Switch back to the integrated terminal from earlier.
- Confirm the terminal prompt ends with weather-converter.
- Delete the weather-converter folder by running these commands:
cd ..
rm -rf weather-converter
ls
What Do These Commands Do?
- The first command moves the terminal to the folder that contains weather-converter.
- The second command permanently removes the project folder.
- The final command lists the remaining items so you can confirm the deletion.
You should no longer see weather-converter in the terminal output.
Still See the Folder?
- Check that the integrated terminal started in the weather-converter folder.
- Help me safely remove the weather-converter folder from its current location on macOS.
Nice Work!
Nice Work!
You did it! Your Python weather converter now demonstrates type conversion through a clear Fahrenheit-to-Celsius report.
You've learned how to:
- Build an interactive weather converter that accepts whole-number, decimal, or negative Fahrenheit temperatures.
- Use input() to capture a temperature as a string. Use type() to confirm its starting type. Use type() again to reveal the converted floating-point number.
- Fix a deliberate type mismatch with float(). Calculate Celsius with the Fahrenheit-to-Celsius formula. Round the result to one decimal place with round(). Format the weather report with an f-string.
- Secret Mission: Add targeted exception handling for nonnumeric input. Replace the traceback with a friendly correction. Keep successful conversions in the else path.
Ready to quiz yourself?