Newbie: strange int() behaviour

Wojtek Walczak gminick at hacker.pl
Tue Dec 3 10:08:42 EST 2002


Dnia Wed, 04 Dec 2002 00:25:32 +1100, Joerg H. Baach napisał(a):
> for i in range (80,100,1):
>     val = fuz.process("temp",i,"speed")
>     half = val /2
>     length = int(half)
>     stars= length * "*"
>     print "%s %s (%f) stars: %s" % (i,stars,val,length)
> print "fertig"

Use round():

for i in range (80,100,1):
    val = fuz.process("temp",i,"speed")
#    half = val /2 # not needed
    length = int(round(val)/2) # here's a change
    stars= length * "*"
    print "%s %s (%f) stars: %s" % (i,stars,val,length)

HTH.

-- 
[ ] gminick (at) underground.org.pl  http://gminick.linuxsecurity.pl/ [ ]
[ "Po prostu lubie poranna samotnosc, bo wtedy kawa smakuje najlepiej." ]



More information about the Python-list mailing list