Temperature Converter with Python

Temperature Converter with Python

Instructions

This is a fun project to create a temperature converter with Python. Your job is to write a Python program that converts temperatures from Celsius to Fahrenheit.

  1. The program should prompt the user to enter a temperature in Celsius.
  2. Extract the numerical part of the temperature and convert it to an integer.
  3. Apply the conversion formula to convert Celsius to Fahrenheit: Fahrenheit = (Celsius * 9/5) + 32.
  4. Display the converted temperature in Fahrenheit.

Steps:

  1. Prompt the user to enter a temperature in Celsius.
  2. Read the user input and store it in a variable.
  3. Extract the numerical part of the input temperature using string manipulation.
  4. Convert the extracted temperature to an integer using the “int()” function.
  5. Apply the conversion formula to convert Celsius to Fahrenheit.
  6. Print the converted temperature in Fahrenheit.

Expected Output

## Input:
Please enter a temeperature in celsius: 35

## Output:
"The temperature in Fahrenheit is: 95.0°F"

 

Source code

# Step 1: Prompt the user to enter a temperature in Celsius
celsius = input("Enter a temperature in Celsius: ")

# Step 2: Extract the numerical part of the input temperature
numeric_part = ""
for char in celsius:
    if char.isdigit() or char == '.':
    numeric_part += char

# Step 3: Convert the extracted temperature to an integer
celsius_temp = int(float(numeric_part))

# Step 4: Apply the conversion formula to convert Celsius to Fahrenheit
fahrenheit_temp = (celsius_temp * 9/5) + 32

# Step 5: Print the converted temperature in Fahrenheit
print(f"The temperature in Fahrenheit is: {fahrenheit_temp}°F")

Python Practice

Keep practicing, try also other Python exercises and level up your coding skills.

We will be happy to hear your thoughts

Leave a reply

Python and Excel Projects for practice
Register New Account
Shopping cart