Bottom Page

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?
Quote
#2
I'm surprised you got that error. I would have expected an IndentationError due to the function and while block not... existing.
Quote
#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
Quote
#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.
metulburr likes this post
Feel like you're not getting the answers you want? Checkout the help/rules for things like what to include/not include in a post, how to use code tags, how to ask smart questions, and more.

Pro-tip - there's an inverse correlation between the number of lines of code posted and my enthusiasm for helping with a question :)
Quote
#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

Quote
#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
Quote
#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.
Feel like you're not getting the answers you want? Checkout the help/rules for things like what to include/not include in a post, how to use code tags, how to ask smart questions, and more.

Pro-tip - there's an inverse correlation between the number of lines of code posted and my enthusiasm for helping with a question :)
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Powerball assignment, how to get correct output of a dictionary ? msp1981 5 403 Mar-19-2019, 11:02 PM
Last Post: Yoriz
  PowerBall Help nick 3 1,637 Nov-11-2016, 06:59 PM
Last Post: nilamo

Forum Jump:


Users browsing this thread: 1 Guest(s)