[Tutor] celcius to farenheit converter.
rabidpoobear at gmail.com
Wed Apr 18 07:07:39 CEST 2007
Rikard Bosnjakovic wrote:
> On 4/18/07, python at uni-code.com <python at uni-code.com> wrote:
>> I found this site and I'm practicing coding and I write this script, but
>> I'm unsure why its not working. Everything goes well until it gets to the
>> part where it tries to calculate the formula. Inputs work fine anyone
>> know what I did wrong?
> if type == "c":
> cel = (5/9)*(temp_int-32)
5/9 is 0 in Python 2.5 and earlier.
'/' defaults to integer division if both sides are integers as well.
What you'd want to do is 5.0/9 or 5/9.0 or 5.0/9.0 or just 0.555555555
same applies to your 9/5 below.
> print "Farhrenheit %d is equal to %d celcius.\n" % (temp_int, cel)
> elif type == "f":
> far = (9/5)*(temp+32)
More information about the Tutor