February 18th, 2013, 11:04 AM
Join Date: Feb 2013
Time spent in forums: 4 h 45 m 47 sec
Reputation Power: 0
Stuck on simple python prob
I'm a recoverying perl programmer trying to pick up python as part of my current gig. I went out and found some 'practice' problems on the web which don't supply answers. Theoretically, shouldn't need 'em, this one should be simple, but it's got me stumped.
Short version: temperature conversion between celsius and farenheight
Here's the code:
"""Converts Celsius to Farenhieht"""
tf=(9/5 * n) + 32
"""Converts Farenheit to Celsius"""
print "N: " + n
tc = (5/9) * (int(n)-32) ## problem seems to be here
print "TC: %5.2f" % (tc,)
T = 'abc'
while not T.isdigit():
T = raw_input("Enter a temperature: ")
C = 'abc'
while C.upper() not in ['C', 'F']:
C = raw_input("Convert to (F)arenheight or (C)elsius: ")
if C.upper() == 'C':
n = f2c(T)
n = c2f(T)
print "Converted: %3d" % (n,)
When I run it, I get:
Enter a temperature: 80
Convert to (F)arenheight or (C)elsius: c
I'm suspecting some type of integer/string/float conversion issue; however, I've tried all three in the print statement to no avail.
I know the c2f function is borked; I figure I can get that fixed once I figure out what's up with the f2c.
I've apparently missed some fairly basic concept. Can someone point it out to me?