[Tutor] while Loop

Kent Johnson kent37 at tds.net
Wed Jul 18 17:55:21 CEST 2007


Darren Williams wrote:
> Hi all,
>  
> I'm writing a calculator for an online game that I used to play but 
> don't seem to be able to break out of the while loop, the program will 
> just go over and over the loop, crashing the program and I don't know if 
> Python is just really slow at this type of thing or i'm doing it 
> completely wrong in Python (the equivalent code in JavaScript works fine).
>  
> Python code -
>  
> def main():
>     usedPocketsOne = 192000
>     junkiesOne = 500
>     labSpaceOne = 0
>  
>     resultOne = 0
>     while usedPocketsOne > (junkiesOne - labSpaceOne) * 17:
>         resultOne = resultOne + 1
>         usedPocketsOne = (UsedPocketsOne - junkiesOne + labSpaceOne) * 17

Maybe this should be
          usedPocketsOne = UsedPocketsOne - junkiesOne + labSpaceOne * 17

which is what you have in the JS.

Kent

>         junkiesOne = junkiesOne + 1
>  
> main()
>  
> And the JavaScript equivalent (incase there are any stalwarts beside 
> Alan here) -
>  
> function main() {
> var usedPocketsOne = 192000
> var junkiesOne = 500
> var labSpaceOne = 0
>  
> var resultOne = 0
> while (usedPocketsOne > junkiesOne - labSpaceOne * 17) {
>     resultOne = resultOne + 1
>     usedPocketsOne = usedPocketsOne - junkiesOne + labSpaceOne * 17
>     junkiesOne = junkiesOne + 1
> }
> }
>  
> Thanks in advance for any help :)
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor



More information about the Tutor mailing list