Ive been working on this tempeture converter but have been troubling conbining the two programs (Celsius to Fahrenheit) and (Fahrenheit to Celsius), i can get the display menu to print but cant manage to figure out how to select a converter.
# Tempeture Converter
def convert():
print 'Conversions Menu';
print '(1) Celsius to Fahrenheit';
print '(2) Fahrenheit to Celsius';
def select():
convert();
choice = input ('Enter Choice Number:')
if (input == '1'):
C2F();
elif (input == '2'):
F2C();
def F2C():
Fahrenheit = input('enter degrees in Fahrenheit: ');
Celsius = ( 5.0 / 9.0) * (Fahrenheit -32);
print Fahrenheit, 'Fahrenheit =', Celsius, 'Celsius';
def C2F():
Celsius = input('enter degrees in Celsius: ');
Fahrenheit = (9.0 / 5.0) * Celsius +32;
print Celsius, 'Celsius =', Fahrenheit, 'Fahrenheit';
*Correction*
# Tempeture Converter
def convert():
print 'Conversions Menu';
print '(1) Celsius to Fahrenheit';
print '(2) Fahrenheit to Celsius';
def select():
convert();
choice = input ('Enter Choice Number:')
if (choice == '1'):
C2F();
elif (choice == '2'):
F2C();
def F2C():
Fahrenheit = input('enter degrees in Fahrenheit: ');
Celsius = ( 5.0 / 9.0) * (Fahrenheit -32);
print Fahrenheit, 'Fahrenheit =', Celsius, 'Celsius';
def C2F():
Celsius = input('enter degrees in Celsius: ');
Fahrenheit = (9.0 / 5.0) * Celsius +32;
print Celsius, 'Celsius =', Fahrenheit, 'Fahrenheit';
You should be using
raw_inputinstead ofinput,inputwill try to wrap whatever you type inevalto convert it to Python code, so when you enter ‘1’ or ‘2’ it will be converted to an integer, but you are still trying to compare to strings.Combine that with what Paul mentioned about
choiceinstead ofinputand you should have a working solution.Also, drop all of the semi-colons and the parentheses in your conditionals, they aren’t necessary in Python: