Description:
This is a very simple temperature converter using Python 3.3.2. It uses the command prompt, similar to Visual Basic.Net's console application.
Notes:
You can easily convert this to compile with Python 2, just change input() to raw_input()
Plans:
I plan to properly parse the numeric datatypes. Currently I'm just using int([string]), which is fine if the user enters in a numeric data type, but if the user enters in a non-numeric character then it will crash the program.
Source:
Python Code:
#The Fahrenheit to Celsius and Vice-Versa Functions
def f_to_c(f):
return (f - 32) * 5 / 9
def c_to_f(c):
return c * 9 / 5 + 32
main = True
while main == True:
val = int(input("Please enter in the degrees you wish to convert: "))
#This prints out:
#Which would you like to do?
#Convert Fahrenheit to Celsius: 1
#Convert Celsius to Fahrenheit: 2
#
#
response = input("Which would you like to do?\nConvert Fahrenheit to Celsius: 1\nConvert Celsius to Fahrenheit: 2\n\n")
valid = False
while valid == False:
if response == "1":
c = f_to_c(val)
valid = True
print (str(val) + " degrees Fahrenheit is " + str(c) + " degrees Celsius\n")
elif response == "2":
f = c_to_f(val)
valid = True
print (str(val) + " degrees Celsius is " + str(f) + " degrees Fahrenheit\n")
else:
print ("Invalid Input")