Conversion code not working properly

weasel healthed at hotmail.com
Sun Feb 22 14:45:30 EST 2004


It's not working. I don't think the conversion is the problem. After
converting, the program shows the original entry you put in

i.e. Please enter low temp:
32
Please enter high temp:
42
Please enter a conversion letter (C, F):
F

Then, the display shows
32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42

However,

the conversion is only showing 
0, 1, 2, 3, 4, 5.

What happened to the other half? I tried using 5.0/9.0, but got the
same results.

Any more ideas?


On Sun, 22 Feb 2004 20:32:50 +0100, Andrei <fake at fake.net> wrote:

>weasel wrote on Sun, 22 Feb 2004 19:07:01 GMT:
>
>> Why is the Farenheit to Celsius part not working properly? Instead of
>> showing a similar range of what the farenheit is listing, the celsius
>> portion is showing half the range of farenheit.
>
>Try this in your interactive interpreter:
>
>>>> 9/5
>
>What's odd about the result? "/" does integer division. It's weird and
>unexpected to lots of people, but it's the way it is - it will be fixed in
>due time. However, due to some time machine Guido is said to possess, you
>can already use the future behavior by doing this:
>
>from __future__ import division
>
>Then try 9/5 again. Integer division is "//" now, while "/" behaves as
>floating-point division.
>
>Alternatively, you could use a floating-point number instead of integers.
>Try this in a clean interpreter session (without the from __future__
>thing):
>
>>>> 9.0/5
>>>> 9/5.0
>>>> 9.0/5.0
>
><snip>         
>>         low_other_temp = (9 / 5 * low) + 32
>>         high_other_temp = (9 / 5 * high) + 32
>>         rnge = range(low, high + 1)
>>         faren = range(low_other_temp, high_other_temp + 1)  
>>         print rnge
>>         print faren
>>    
>>     elif temp == 'F' and low <= high:
>> 
>>         num1 = low - 32
>>         num2 = high - 32
>>         low_temp = num1 * 5/9
>>         high_temp = num2 * 5/9
>>         rnge = range(low, high + 1)
>>         celsi = range(low_temp, high_temp + 1)
>>         print rnge
>>         print celsi
><snip>




More information about the Python-list mailing list