You can mail me Contact Me!

Convert temperature values back and forth between Celsius (C) and Fahrenheit (F)

Python codes for converting temperature values back and forth between Celsius (C) and Fahrenheit (F)

 Algorithm:

  1. Start
  2. Display menu options
    • Option 1: Celsius to Fahrenheit
    • Option 2: Fahrenheit to Celsius
  3. Get user's choice (1 or 2)
  4. If choice is 1:
    • Get temperature in Celsius
    • Calculate Fahrenheit = (Celsius × 9/5) + 32
    • Display result
  5. If choice is 2:
    • Get temperature in Fahrenheit
    • Calculate Celsius = (Fahrenheit - 32) × 5/9
    • Display result
  6. If invalid choice:
    • Display error message
  7. End


Hello, dear reader! 👋

Thanks for visiting my blog! I’m a student just like you, sharing what I learn to help others with Python programming. I hope my posts are useful for your studies! 😊

If you find this post helpful, please leave a comment—even just a few emojis will make my day! 🐍✨ Your feedback keeps me motivated to create more content for everyone. 🚀

Happy programming!
Abhin Krishna, S01, EB Department, MEC


Pseudocode:

BEGIN
    DISPLAY "Temperature Conversion:"
    DISPLAY "1. Convert Celsius to Fahrenheit"
    DISPLAY "2. Convert Fahrenheit to Celsius"
    INPUT choice
    
    IF choice = "1" THEN
        INPUT celsius
        fahrenheit ← (celsius × 9/5) + 32
        DISPLAY celsius + "°C is equal to " + fahrenheit + "°F"
    
    ELSE IF choice = "2" THEN
        INPUT fahrenheit
        celsius ← (fahrenheit - 32) × 5/9
        DISPLAY fahrenheit + "°F is equal to " + celsius + "°C"
    
    ELSE
        DISPLAY "Invalid choice. Please enter 1 or 2"
    END IF
END

Program:


# Temperature Conversion Program

print("\nTemperature Conversion:")
print("1. Convert Celsius to Fahrenheit")
print("2. Convert Fahrenheit to Celsius")
choice = input("Enter your choice (1/2): ")

if choice == '1':
    # Convert Celsius to Fahrenheit
    celsius = float(input("Enter temperature in Celsius: "))
    fahrenheit = (celsius * 9/5) + 32
    print(f"{celsius}°C is equal to {fahrenheit}°F")

elif choice == '2':
    # Convert Fahrenheit to Celsius
    fahrenheit = float(input("Enter temperature in Fahrenheit: "))
    celsius = (fahrenheit - 32) * 5/9
    print(f"{fahrenheit}°F is equal to {celsius}°C")

else:
    print("Invalid choice. Please enter 1 or 2")
Flowchart:


Important!
If you find any mistakes in my code or flowchart, please comment below this post. I will be happy to correct them and clear up any doubts you may have.

Post a Comment

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
Site is Blocked
Sorry! This site is not available in your country.