Convert Celsius to Fahrenheit in Python
The following example demonstrates how to convert Celsius temperature to Fahrenheit.
Example:
# -*- coding: UTF-8 -*- # User input for Celsius temperature celsius = float(input('Enter temperature in Celsius: ')) # Convert Celsius to Fahrenheit fahrenheit = (celsius * 1.8) + 32 print('%0.1f Celsius is equal to %0.1f Fahrenheit' % (celsius, fahrenheit))
When the above code is executed, it prompts the user to enter a temperature in Celsius and then converts it to Fahrenheit using the formula.
Output:
Enter temperature in Celsius: 38 38.0 Celsius is equal to 100.4 Fahrenheit
In this example, the formula used to convert Celsius to Fahrenheit is:
The reverse calculation for converting Fahrenheit to Celsius is: