[Tutor] [Fwd: Re: powerball]

Marilyn Davis marilyn at deliberate.com
Thu Jun 12 07:14:19 CEST 2008


Hi Max and everyone,

Max, your reply-to only went to me.  You have to work harder to get it to
go to the whole list.

Anyway, my advice is to post your new program and see what people say.

Marilyn

---------------------------- Original Message ----------------------------
Subject: Re: [Tutor] powerball
From:    "max baseman" <dos.fool at gmail.com>
Date:    Wed, June 11, 2008 7:22 pm
To:      "Marilyn Davis" <marilyn at deliberate.com>
--------------------------------------------------------------------------

thank you for your help i beleave i have fixed this bug and made the
script slightly shorter yet i seem to have run into another bug i
cant find - the program now just eats my ram and doesn't seem to run
correctly now it displays no output and nearly freezes my computer
i'm still looking for the reason but if you have the time i would
appreciate you advise

- thanks





On Jun 11, 2008, at 12:36 PM, Marilyn Davis wrote:

> On Wed, June 11, 2008 9:58 am, max baseman wrote:
>
> Hi Max,
>
> Here's your code with the indents preserved.  I'll make my comments
> with >'s.
>
> from random import randrange
> wins=0
> win=[]
> count =0
> while count !=5:
>
>>  To loop 5 times it is better to use:
>
>>  for count in range(5):
>>       stuff you want to do
>
>>  Then all the loop controlling happens in one place and it is hard to
>>  mess up.
>
>      number=randrange(55)+1
>      win.append(number)
>      count=count+1
> powerball=randrange(42)+1
> count=0
> win.sort()
> while count !=146107962:
>      numbers=[]
>      count2=0
>      while count2 !=5:
>          number=randrange(55)+1
>
>>  Yep, indeed, here you made the easy mistake of forgetting to + 1 to
>>  count2.  So, it probably spun forever right there.
>
>>  I also don't see that "count" is every changed, so that would be
>> another
>>  spin.  All these would go away by using 'for' 'in' and 'range'.
>
>>  It looks like a fun program and a good start.
>
>>  Marilyn Davis
>
>      if number in win:
>          numbers.append(number)
>      else:
>          print "lose"
>          break
>      numbers.sort()
>      ball=randrange(42)+1
>      if ball==powerball:
>          print "win"
> print
> print
> print win, powerball
>
>> as a fun little project i scripted a powerball program. it seems
>> to have a
>> bug in it that i cant find.
>>
>> from random import randrange wins=0 win=[] count =0 while count !=5:
>> number=randrange(55)+1 win.append(number) count=count+1
>> powerball=randrange(42)+1 count=0 win.sort() while count !=146107962:
>> numbers=[] count2=0 while count2 !=5: number=randrange(55)+1 if
>> number in
>> win:
>> numbers.append(number) else:
>> print "lose" break numbers.sort() ball=randrange(42)+1 if
>> ball==powerball:
>> print "win" print print print win, powerball
>>
>>
>>
>>
>> _______________________________________________
>> Tutor maillist  -  Tutor at python.org
>> http://mail.python.org/mailman/listinfo/tutor
>
>


-------------- next part --------------
A non-text attachment was scrubbed...
Name: powerball.py
Type: text/x-python-script
Size: 555 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/tutor/attachments/20080611/9016d19b/attachment-0001.bin>


More information about the Tutor mailing list