Python Forum
Powerball script help
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Powerball script help
#1
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?
Reply
#2
I'm surprised you got that error. I would have expected an IndentationError due to the function and while block not... existing.
Reply
#3
(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
Reply
#4
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.
Reply
#5
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.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#6
(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
Reply
#7
(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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Powerball List jackthechampion 1 2,442 Apr-13-2020, 06:02 PM
Last Post: deanhystad
  Powerball assignment, how to get correct output of a dictionary ? msp1981 5 3,219 Mar-19-2019, 11:02 PM
Last Post: Yoriz
  PowerBall Help nick 3 4,727 Nov-11-2016, 06:59 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020