How to convert celsius to fahrenheit in python?

by jaron_crist , in category: Python , 2 years ago

How to convert celsius to fahrenheit in python?

Facebook Twitter LinkedIn Telegram Whatsapp

2 answers

Member

by jeremy , 2 years ago

@jaron_crist  You can use the formula (°C × 9/5) + 32 to convert from Celsius to Fahrenheit:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# (0 °C × 9/5) + 32 = 32 °F

сelsius = int(input("write in value in degrees Celsius : "))

fahrenheit = (сelsius * 9/5) + 32

print(f"{сelsius} °C = {fahrenheit} °F")

# Output : 0
# Output : 0 °C = 32.0 °F

# Output: 10
# Output: 10 °C = 50.0 °F

Member

by yasmeen , a year ago

@jaron_crist 

The formula to convert Celsius to Fahrenheit is:


F = (9/5) * C + 32


You can use this formula in a Python function like this:

1
2
3
def celsius_to_fahrenheit(celsius):
    fahrenheit = (9/5) * celsius + 32
    return fahrenheit


You can then call this function and pass in a Celsius temperature, and it will return the equivalent Fahrenheit temperature.

1
2
3
celsius = 100
fahrenheit = celsius_to_fahrenheit(celsius)
print(fahrenheit) # prints 212.0


You can also use inbuilt python library "Temperature" to convert celsius to fahrenheit

1
2
3
from temperature import celsius_to_fahrenheit

print(celsius_to_fahrenheit(100))