Python Project: Temperature Converter

Project Description

Create a converter from Fahrenheit to celsius using the formula

°𝐶=(°𝐹−32)×5/9

Project

  • Prompt the user for temperature in Fahrenheit
  • Calculate the temperature in Celsius
  • Print the result

Examples

  • 75 → 23.89

Step 1 Prompt the user

You can use the built-in function input() to prompt the user. Notice that it returns a string, which needs to be converted to float for further calculations. That can be done with the built-in function float().

# 1: prompt the user
fahrenheit_str = input('Input Fahrenheit: ')
fahrenheit = float(fahrenheit_str)

Step 2 Calculate the celsius temperature

We will use the formula. Notice that you can use round() to get 2 digits (or any number of precision if you change the second argument).

°C=(°F−32)×5/9

# 2: Caculate the celsius temperature
celsius = (fahrenheit - 32)*5/9
celsius = round(celsius, 2)

Step 3 Display the result

You can use the built-in function print() to display the result to the user.

# 3: dispaly result
print('Celsius', celsius)

The full code

The full code is given here.

# 1: prompt the user
fahrenheit_str = input('Input Fahrenheit: ')
fahrenheit = float(fahrenheit_str)
# 2: Caculate the celsius temperature
celsius = (fahrenheit - 32)*5/9
celsius = round(celsius, 2)
# 3: dispaly result
print('Celsius', celsius)

Learn Python

Learn Python A BEGINNERS GUIDE TO PYTHON

  • 70 pages to get you started on your journey to master Python.
  • How to install your setup with Anaconda.
  • Written description and introduction to all concepts.
  • Jupyter Notebooks prepared for 17 projects.

Python 101: A CRASH COURSE

  1. How to get started with this 8 hours Python 101: A CRASH COURSE.
  2. Best practices for learning Python.
  3. How to download the material to follow along and create projects.
  4. A chapter for each lesson with a descriptioncode snippets for easy reference, and links to a lesson video.

Expert Data Science Blueprint

Expert Data Science Blueprint

  • Master the Data Science Workflow for actionable data insights.
  • How to download the material to follow along and create projects.
  • A chapter to each lesson with a Description, Learning Objective, and link to the lesson video.

Machine Learning

Machine Learning – The Simple Path to Mastery

  • How to get started with Machine Learning.
  • How to download the material to follow along and make the projects.
  • One chapter for each lesson with a Description, Learning Objectives, and link to the lesson video.

2 thoughts on “Python Project: Temperature Converter”

Leave a Comment