Q:

Python program to convert temperature from Celsius to Fahrenheit and vice-versa

belongs to collection: Python basic programs

0

Formula used:

    
    Celsius to Fahrenheit:  °C= (5/9)*(°F-32)
    Fahrenheit to Celsius:  °F= (9/5)*(°C) + 32

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Code:

# Define a function to convert
# celsius temperature to Fahrenheit
def Celsius_to_Fahrenheit(c) :
    
    f = (9/5)*c + 32
    
    return f
    
# Define a function to convert
# Fahrenheit temperature to Celsius
def Fahrenheit_to_Celsius(f) :
    
    c = (5/9)*(f - 32)
    
    return c
    

# Driver Code
if __name__ == "__main__" :
    
    c = 36
    print(c, "degree celsius is equal to:",Celsius_to_Fahrenheit(c),"Fahrenheit")
    
    f = 98
    print(f,"Fahrenheit is equal to:",Fahrenheit_to_Celsius(f),"degree celsius")

Output

    36 degree celsius is equal to: 96.8 Fahrenheit
    98 Fahrenheit is equal to: 36.66666666666667 degree celsius

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Python basic programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Python program to find the number of required bits... >>
<< Python program for Zip, Zap and Zoom game...