Tags

Related Posts

Share This

Temperature.py in Python

A module that asks the user the following question:
Press C to convert Celcius to Fahrenheit
Press F to convert Fahrenheit to Celcius:
Note: You have to make sure to accept either lowercase or uppercase C's and F's.
Then it will use the mathematical formula for the conversion and print out something like this:
X degree Celcius == y degree Fahrenheit and vise versa.
My answer is:
choice = raw_input(‘Enter Temp in (C)elsius or (F)ahrenheit to Convert to the other: ‘)
if choice == ‘c’:
x = input (‘Give me the Temp in Celsius: ‘)
print “The Temp in F is” , (9.0/5.0) * (x + 32) , “degrees”
elif choice == ‘C’:
x = input (‘Give me the Temp in Celsius: ‘)
print “The Temp in F is” , (9.0/5.0) * (x + 32) , “degrees”
elif choice == ‘f’:
x = input (‘Give me the Temp in Fahrenheit: ‘)
print “The Temp in C is” , (x – 32) * (5.0/9.0) , “degrees”
elif choice == “F”:
x = input (‘Give me the Temp in Fahrenheit: ‘)
print “The Temp in C is” , (x – 32) * (5.0/9.0) , “degrees”
else:
print “You must give temperature in C or F”