Python Program to convert Celsius to Fahrenheit

Python Program – Convert Celsius to Fahrenheit

To convert Celsius to Fahrenheit, you can use the following formula in the program.

Fahrenheit = (Celsius * 9 / 5) + 32

Let us write a function, that takes the Celsius value as argument, computes the Fahrenheit using the above formula, and return the result.

def celsiusToFahrenheit(c):
    return (c * 9 / 5) + 32

You may use this function, in your program, to convert Celsius to Fahrenheit.

The following is an example program, where we shall use the above conversion function, and convert 32 Celsius to Fahrenheit and print the result to output.

Python Program

# Function that converts C to F
def celsiusToFahrenheit(c):
    return (c * 9 / 5) + 32

if __name__ == "__main__":
    # Given Celsius
    c = 37

    # Convert Celsius to Fahrenheit
    f = celsiusToFahrenheit(c)

    print(f"{c} Celsius is equal {f} Fahrenheit")
Run Code Copy

Output

37 Celsius is equal 98.6 Fahrenheit

To verify your output, you can use this online tool: Convert Celsius to Fahrenheit online by ConvertOnline.org.

Code copied to clipboard successfully 👍