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]
[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]