Temperature Conversion

A code to convert Celsius to Fahrenheit and vice versa.

Welcome to the code! This code helps the beginners to use a while loop to convert Celsius to Fahrenheit and vice versa in a user-friendly way.

In this code, the most important line of code that we need to know is the formulas for the conversion of the temperatures. Further, we use a while loop to make the conversion depending on the user’s choice.

Celsius to Fahrenheit: fahrenheit = (celsius * 1.8) + 32
Fahrenheit to Celsius: celsius = (fahrenheit – 32) / 1.8

Note: Loved the post? You too can publish your article on “Python for fun” which will be loved by millions. Contribute an article!

					repeat = "yes"

while repeat == "yes" or repeat == "y":
    print("1. Convert Celsius to Fahrenheit")
    print("2. Convert Fahrenheit to Celsius")
    choice = int(input("Choose the conversion---"))

    if choice == 1:
        celsius = float(input("Enter the celsius value---"))
        fahrenheit = (celsius * 1.8) + 32
        print(celsius," degree Celsius is equal to ",fahrenheit," degree Fahrenheit")
    elif choice == 2:
        fahrenheit = float(input("Enter the fahrenheit value---"))
        celsius = (fahrenheit - 32) / 1.8
        print(fahrenheit," degree fahrenheit is equal to ",celsius," degree celsius")
        print("Wrong Input. Choose again!")
        repeat = "yes"
    repeat = input("Do you want to convert again?")
Share on facebook
Share on whatsapp
Share on pinterest
5 3 votes
Notify of
Inline Feedbacks
View all comments