In this post, we will learn how to convert Celsius to Fahrenheit in Python with detailed explanation and example. This program helps you to understand the basic concepts of Python so let’s start from very basic, we will discuss the formulas first after that we will jump into the programming part.
Formula to Convert Celsius to Fahrenheit
This is the formula that will help us to convert Celsius to Fahrenheit.
Steps to Convert Celsius to Fahrenheit
- Ask the user to enter the temperature in Celsius (
c
). - Apply the formula of Fahrenheit (
f = (c*(9/5))+32
). - print the result (
print(f)
).
Now we know how to implement the program but before writing it few programming concepts you have to know such as:
Source Code
c = float(input("Enter Temperature in Celsius: "))
f = (c*(9/5))+32
print(f"Temperature in Fahrenheit: {f:.2f} F")
Output
Enter Temperature in Celsius: 33.3
Temperature in Fahrenheit: 91.94 F
Let’s modify this program and write it using Function.
Python program to Convert Celsius to Fahrenheit Using Function
# Function defination
def celsius_to_fahrenheit(c):
return (c*(9/5))+32
# main body
c = float(input("Enter Temperature in Celsius: "))
# calling a Function
f = celsius_to_fahrenheit(c)
print(f"Temperature in Fahrenheit: {f:.2f} F")
Output
Enter Temperature in Celsius: 15
Temperature in Fahrenheit: 59.00 F