Temperature Converter 2 posts

OP Tue Jul 16, 2013 5:14 am
User avatar
Master
Legendary Family Member
  • Gender: Male
  • Posts: 529
  • Joined: Jul, 2011
  • Karma: 10
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]
Sun Dec 10, 2017 12:35 am
User avatar
  • Posts: 51
  • Joined: Dec, 2017
  • Karma: 1
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