Write a Python Program to Convert Celsius to Fahrenheit. Before going into the example, let me show you the mathematical formula to Convert C to F is Fahrenheit = (Celsius * 9/5) + 32. Otherwise, you can replace the 9/5 with 1.8.
Python Program to Convert Celsius to Fahrenheit
This Python example allows entering the temperature in Celsius and converting it to Fahrenheit using the above-mentioned math formula.
celsius = float(input("Please Enter the Temperature in Celsius = ")) fahrenheit = (1.8 * celsius) + 32 //fah = ((cel * 9)/5) + 32 print("%.2f Celsius Temperature = %.2f Fahrenheit" %(celsius, fahrenheit))
Convert C to F using Functions.
This example is the same as the above. However, we used the functions.
def ctof(c): f = (c * 9/5) + 32 return f c = float(input("Enter the Temperature in Celsius = ")) f = ctof(c) print("%.2f Degrees Celsius Temperature = %.2f Fahrenheit" %(c, f))
Enter the Temperature in Celsius = 28
28.00 Degrees Celsius Temperature = 82.40 Fahrenheit