[Tutor] while Loop

Darren Williams D3IBZ at hotmail.com
Wed Jul 18 17:46:09 CEST 2007


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
        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 :)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070718/9cdbe4cf/attachment.htm 


More information about the Tutor mailing list