Ad:
 
  • Python Discussion Thread
  • Unsolved
  • Views: 318
  • Python RSS
Similar Threads
May 19th, 2010
0

BlackJack Help

Expand Post »
I have done the blackjack program but every time i run it shows an error here is the code:
P.S. I also need to show the value of the card[names of the cards e.g Jack etc

Python Syntax (Toggle Plain Text)
  1. import random as r
  2. def define_cards(c):
  3. rank_suit=["ace","two","three","four","five","six","seven","eight","nine","ten","jack","queen","king"]
  4. suit_rank=["clubs","spades","heatrts","diamonds"]
  5. for suit in range(4):
  6. for rank in range(13):
  7. card_string=rank_suit[rank]+ " of "+ suit_rank[suit]
  8. c.append(card_string)
  9. return
  10. def create_deck():
  11. for i in range (52):
  12. print[deck], i
  13. deck = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10]*4
  14. dealer = []
  15. Player = []
  16.  
  17.  
  18. def showHand():
  19. hand = 0
  20. for i in player: hand += i
  21. print "The dealer is showing a %d" % dealer[0]
  22. print "Your hand totals: %d (%s)" % (hand, Player)
  23.  
  24. def setup():
  25. for i in range(2):
  26. dealDealer = deck.append (r.randint(1, len(deck)-1)
  27. dealplayer = deck.append(r.randint(1, len(deck)-1)
  28. dealer.append(dealDealer)
  29. Player.append(dealPlayer)
  30. deck.pop(dealDealer)
  31. deck.pop(dealPlayer)
  32. setup()
  33. ans=0
  34. while ans != 'yes':
  35. showHand()
  36. ans = raw_input("Do you want to play another game: ")
  37.  
  38. if ans != 'yes':
  39. dealPlayer = deck[r.randint(1, len(deck)-1)]
  40. player.append(dealPlayer)
  41. deck.pop(dealPlayer)
  42. hand = 0
  43. for i in dealer: hand += i
  44. if not hand > 17:
  45. dealDealer = deck[r.randint(1, len(deck)-1)]
  46. dealer.append(dealDealer)
  47. deck.pop(dealDealer)
  48. hand = 0
  49. for i in player: hand += i
  50. if hand > 21:
  51. print "BUST!"
  52. Player = []
  53. dealer = []
  54. setup()
  55. hand = 0
  56. for i in dealer: hand +=i
  57. if hand > 21:
  58. print "Dealer Busts!"
  59. Player = []
  60. dealer = []
  61. setup()
  62. elif ans== 'no':
  63. dHand = 0
  64. PHand = 0
  65. for i in dealer: dHand += i
  66. for i in Player: pHand += i
  67. if pHand > dHand:
  68. print "the dealer is busted!"
  69. dealer = []
  70. Player = []
  71. setup()
  72. else:
  73. print "you are busted!"
  74. dealer = []
  75. Player = []
  76. setup()
  77. print
jib
Reputation Points: 5
Solved Threads: 0
Newbie Poster
jib is offline Offline
17 posts
since May 2010
May 19th, 2010
0

Re: BlackJack Help

You should give more information about the error (line, type, etc) so we could come up with a solution without running it. There is a SyntaxError at line 28 and 29, one closing bracket is missing. You should turn highlighting matching brackets on in your text editor/IDE There is another error at line 29 (dealPlayer instead of dealplayer). Still not done, at line 26 and 27 there is an unclear part: append does not have a return value. I don't really know what you meant to do here. Tell me, so I can probably fix it.

I also have a suggestion: you should store rank_suit and suit_rank as global variables, so they don't have to be initialized multiple times.
Last edited by sandorlev; May 19th, 2010 at 11:04 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sandorlev is offline Offline
19 posts
since Jan 2010
May 19th, 2010
0

Re: BlackJack Help

So what you are you are saying is i need to change line 26 and 27? which i've already tried and it still gives back the same error.
jib
Reputation Points: 5
Solved Threads: 0
Newbie Poster
jib is offline Offline
17 posts
since May 2010
May 19th, 2010
0

Re: BlackJack Help

You have to add closing brackets, because this is still open:
Python Syntax (Toggle Plain Text)
  1. (r.randint(1, len(deck)-1)
  2. 1 2 3 1 2 (3)

But this line
Python Syntax (Toggle Plain Text)
  1. dealDealer = deck.append (r.randint(1, len(deck)-1)
makes no sense: it's like saying dealDealer = None. What do you want to do here?
Last edited by sandorlev; May 19th, 2010 at 3:29 pm.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sandorlev is offline Offline
19 posts
since Jan 2010
May 19th, 2010
0

Re: BlackJack Help

Have you tried ever making a game if blackjack where the dealer plays against the player as it is this is one of a kind and that is how you deal cards to the dealer that is not the major problem bro it is something else entirely different.

P.S. If it becomes too hard to solve forget it i will start a new version of it.
jib
Reputation Points: 5
Solved Threads: 0
Newbie Poster
jib is offline Offline
17 posts
since May 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: invalid syntax error
Next Thread in Python Forum Timeline: filter out specific words in the text file





About Us | Contact Us | Advertise | Acceptable Use Policy
Build Custom RSS Feed


Follow us on Twitter


© 2010 DaniWeb® LLC