Python Forum

Full Version: Powerball script help
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Having a problem and here it is
def playPowerBall():
while x:
fa = random.sample(range(1,69), 6)
return fa

The problem i am running into is 
UnboundLocalError: local variable 'fa' referenced before assignment 

Any help?
I'm surprised you got that error. I would have expected an IndentationError due to the function and while block not... existing.
(Nov-11-2016, 07:37 PM)nilamo Wrote: [ -> ]I'm surprised you got that error. I would have expected an IndentationError due to the function and while block not... existing.
Yeah i dont really know lol im confused
Use code tags in the future (which preserve indentation). You should also ensure that the code you post can reproduce the problem you're asking about. There's no permutation of indentation that can reproduce the problem you saw. If you make a proper post, we should definitely be able to help though.
It's a good thing your program doesn't work. If it did, it would be an infinite loop.

Hints: Pass x to the function as a parameter. Check for x evaluating to false, because in that case, fa is not defined/infinite loop. Change x in the loop, or you'll never get out of it. Or use a for loop, which is what you probably need.

Note that this program will also fail generate some correct Powerball numbers. The sixth and final Powerball number (the actual Powerball), is drawn from a separate set, and can be a duplicate of the other numbers. You program does not allow for that. Also, the Powerball is in the range 1-26, not 1-69.
(Nov-11-2016, 07:48 PM)ichabod801 Wrote: [ -> ]It's a good thing your program doesn't work. If it did, it would be an infinite loop. Hints: Pass x to the function as a parameter. Check for x evaluating to false, because in that case, fa is not defined. Note that this program will also fail generate some correct Powerball numbers. The sixth and final Powerball number (the actual Powerball), is drawn from a separate set, and can be a duplicate of the other numbers. You program does not allow for that. Also, the Powerball is in the range 1-26, not 1-69.
My teacher weants us to make it like this. This same exact code works at my school but not on my computer idk why
(Nov-11-2016, 07:49 PM)nick Wrote: [ -> ]My teacher weants us to make it like this. This same exact code works at my school but not on my computer idk why
The code, as posted, is a syntax error. Use code tags. Look at it, make sure it looks exactly as it should. Then tell us exactly what result you're having from exactly that code.