0% found this document useful (0 votes)
100 views3 pages

P01 - Fahrenheit To Celsius and Vice Versa

Uploaded by

CRITERION II
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
100 views3 pages

P01 - Fahrenheit To Celsius and Vice Versa

Uploaded by

CRITERION II
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

1.

Python Program to convert the given temperature from Fahrenheit to Celsius and vice versa depending

upon user’s choice.

Aim : To convert the given temperature from Fahrenheit to Celsius and vice versa depending upon user’s

choice.

Procedure:

Step 1: Open Python IDE.

Step 2: Create an infinite loop

Step 3: Print the Choices

Step 4: Get the Choice

Step 5: check the choice using if…elif statement

Step 6: if the choice is 1 then get Celsius, convert it into Fahrenheit and Display the Result

Step 7: if the choice is 2 then get Fahrenheit, convert it into Celsius and Display the Result

Step 8: if the choice is 3 then break the infinite loop and Display Success and Stop the Program

Step 9: otherwise Display Error Message

Step 10: the control will transfer to the next iteration to the infinite loop

Result: Program to convert the given temperature from Fahrenheit to Celsius and vice versa depending upon
user’s choice is done successfully.
Program:

# Python Program to convert the given temperature from Fahrenheit to


# Celsius and vice versa depending upon user’s choice.

while(True):
print("\n1.Celsius to Fahrenheit ")
print("2.Fahrenheit to Celsius ")
print("3.Exit")
ch=int(input("Enter your choice:"))
if ch==1:
# Input
celsius = float(input("Enter temperature in Celsius: "))

# Convert Celsius to Fahrenheit


fahrenheit = (celsius * 9/5) + 32

# Display the result


print("\nTemperature in Fahrenheit:", fahrenheit)
elif ch==2:
# Input
fahrenheit = float(input("Enter temperature in Fahrenheit: "))

# Convert Fahrenheit to Celsius


celsius = (fahrenheit - 32) * 5/9

# Display the result


print("\nTemperature in Celsius:", celsius)

elif ch==3:
break;
else:
print("\nInvalid Choice. Choice should be 1 or 2 or 3.")
print("Success.")
Output:
>>>
1.Celsius to Fahrenheit
2.Fahrenheit to Celsius
3.Exit
Enter your choice:1
Enter temperature in Celsius: 20

Temperature in Fahrenheit: 68.0

1.Celsius to Fahrenheit
2.Fahrenheit to Celsius
3.Exit
Enter your choice:2
Enter temperature in Fahrenheit: 68

Temperature in Celsius: 20.0

1.Celsius to Fahrenheit
2.Fahrenheit to Celsius
3.Exit
Enter your choice:4

Invalid Choice. Choice should be 1 or 2 or 3.

1.Celsius to Fahrenheit
2.Fahrenheit to Celsius
3.Exit
Enter your choice:3
Success.
>>>

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy