
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.
- The program should prompt the user to enter a temperature in Celsius.
- Extract the numerical part of the temperature and convert it to an integer.
- Apply the conversion formula to convert Celsius to Fahrenheit: Fahrenheit = (Celsius * 9/5) + 32.
- Display the converted temperature in Fahrenheit.
Steps:
- Prompt the user to enter a temperature in Celsius.
- Read the user input and store it in a variable.
- Extract the numerical part of the input temperature using string manipulation.
- Convert the extracted temperature to an integer using the “int()” function.
- Apply the conversion formula to convert Celsius to Fahrenheit.
- 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.