Author Topic: need python help plz  (Read 1048 times)

0 Members and 1 Guest are viewing this topic.

Offline 0pt1musPr1m3

  • EZ's Asshole
  • Peasant
  • *
  • Posts: 89
  • Cookies: 90
  • Certified Asshole
    • View Profile
need python help plz
« on: January 31, 2015, 05:15:44 am »
.
« Last Edit: September 14, 2015, 04:51:20 am by 0pt1musPr1m3 »
Don't measure yourself by what you have accomplished, but by what you should have accomplished with your ability.

Offline madf0x

  • Knight
  • **
  • Posts: 172
  • Cookies: 50
    • View Profile
Re: need python help plz
« Reply #1 on: January 31, 2015, 05:38:39 am »
bit busy so can't confirm the specifics, but Im pretty sure it's how you are handling your random card pick. For some values of randint aren't matching up with key values in your dict, so none of your if statements are matching the card. Might need to plug in some sort of try, finally,  that prints out the random int and what card it attempts to associate with.

Offline L0aD1nG

  • Peasant
  • *
  • Posts: 83
  • Cookies: 6
  • NeverFear1isHere
    • View Profile
Re: need python help plz
« Reply #2 on: January 31, 2015, 10:15:54 am »
I am inspecting it now and still it runs fine, a printscreen with the actual error would be helpful.
Though I have a suggestion:

Replace this:
Code: (python) [Select]
raw_input('Press Enter to start the game.')

With this:
Code: (python) [Select]
try:
    raw_input('Press Enter to restart the game or Ctrl-C to end it.')
except KeyboardInterrupt:
    print "Game ended."
    break

So there will be a proper way to end the game.
« Last Edit: January 31, 2015, 10:16:19 am by L0aD1nG »

Offline L0aD1nG

  • Peasant
  • *
  • Posts: 83
  • Cookies: 6
  • NeverFear1isHere
    • View Profile
Re: need python help plz
« Reply #3 on: January 31, 2015, 04:29:06 pm »
Code: [Select]
Traceback (most recent call last):
  File "Heads_up.py", line 124, in <module>
    draw_for_button()
  File "Heads_up.py", line 80, in draw_for_button
    if key == player2_card:
UnboundLocalError: local variable 'player2_card' referenced before assignment
root@kali:~/Desktop/Heads_up.py#


Well based on the error you get. Each time this error happens probably the program will never pass from the if statement on line 72, so it appears to has not an initial value and beeing unable to take place on a boolean operation as it has not been set/assigned to hold a value yet.



So you disliked the idea of making an option for exiting the game normally?
This would probably be a game for sick poker players who will never stop playing I guess  :D
« Last Edit: January 31, 2015, 04:31:22 pm by L0aD1nG »

Offline kenjoe41

  • Symphorophiliac Programmer
  • Administrator
  • Baron
  • *
  • Posts: 990
  • Cookies: 224
    • View Profile
Re: need python help plz
« Reply #4 on: January 31, 2015, 04:45:37 pm »
I think just cross check that you card_value dict maps everything in the cards. You could also use some try__except closes which might help you catch afew exceptions and program ways to mitigate them.

You could also get in the practice of specifing what unction should be called as your main function when the script is executed from the commandline.
Code: (python) [Select]
If __name__ == '__main__':
    print_title()
If you can't explain it to a 6 year old, you don't understand it yourself.
http://upload.alpha.evilzone.org/index.php?page=img&img=GwkGGneGR7Pl222zVGmNTjerkhkYNGtBuiYXkpyNv4ScOAWQu0-Y8[<NgGw/hsq]>EvbQrOrousk[/img]

Offline kenjoe41

  • Symphorophiliac Programmer
  • Administrator
  • Baron
  • *
  • Posts: 990
  • Cookies: 224
    • View Profile
Re: need python help plz
« Reply #5 on: January 31, 2015, 07:54:24 pm »
That is alot of nested for loops, ever heard of iterators. Just look them up and see if they can help you out in this case. I am no expert in datastrucures and algorithm design in python, though my opinions are base on datastructures and algorithms in C++ which i am sure couldn't be too different here.
If you can't explain it to a 6 year old, you don't understand it yourself.
http://upload.alpha.evilzone.org/index.php?page=img&img=GwkGGneGR7Pl222zVGmNTjerkhkYNGtBuiYXkpyNv4ScOAWQu0-Y8[<NgGw/hsq]>EvbQrOrousk[/img]