Temperature Converter

Transcribe
by Transcribe · 2 posts
11 years ago in Python
Posted 11 years ago · Author
Just a simple code to learn from. It was one of my first to be written!

[code=python file=Untitled.txt]

print "Celsius to Fahrenheit converter.\n"

#Options
def menu():
conv = input("To convert C to F, type 1\nTo convert F to C, type 2\nTo end the program, type 3\n\nAwaiting command: ")

if conv==1:
CF()
elif conv==2:
FC()
elif conv==3:
from sys import exit
exit()
else:
print "Please enter a valid input.\n"
menu()

#Celcius to Fahrenheit
def CF():
num = float(input("Enter degrees in Celsius: "))
num2 = ((num*9)/5)+32
print "%.2f Celsius are %.2f Fahrenheit\n" %(num, num2)
menu()

#Fahrenheit to Celcius
def FC():
num = float(input("Enter degrees in Fahrenheit: "))
num2 = (num-32)*5/9
print "%.2f Fahrenheit are %.2f Celsius\n" %(num, num2)
menu()

#starts the program basically
menu()[/code]
Posted 6 years ago
Great Help anymore useful tools ?

Create an account or sign in to comment

You need to be a member in order to leave a comment

Sign in

Already have an account? Sign in here

SIGN IN NOW

Create an account

Sign up for a new account in our community. It's easy!

REGISTER A NEW ACCOUNT