I'm very new to python and have been trying to make a multiplayer blackjack game on python for a while now. I've been running into lots and lots of problems and was wondering if you guys could help me with them.
import random
def total(hand):
aces = hand.count(11)
t = sum(hand)
if t > 21 and aces > 0:
while aces > 0 and t > 21:
t -= 10
aces -= 1
return t
Cards = ["2H", "3H", "4H", "5H", "6H", "7H", "8H", "9H", "2C", "3C", "4C", "5C", "6C", "7C", "8C", "9C", "10C", "2S", "3S", "4S", "5S", "6S", "7S", "8S", "9S", "10S", "2D", "3D", "4D", "5D", "6D", "7D", "8D", "9D", "10D", "AH", "JH", "QH", "KH", "AC", "JC", "QC", "KC", "AS", "JS", "QS", "KS", "AD", "JD", "QD", "KD"]
Cards[35] = 11
Cards[36] = 10
Cards[37] = 10
Cards[38] = 10
Cards[39] = 11
Cards[40] = 10
Cards[41] = 10
Cards[42] = 10
Cards[43] = 11
Cards[44] = 10
Cards[45] = 10
Cards[46] = 10
Cards[47] = 11
Cards[48] = 10
Cards[49] = 10
Cards[50] = 10
Players = raw_input("How many players are there?")
for i in range Players:
Player i = []
Player i.append(choice(Cards))
Player i.append(choice(Cards))
tp = total(player)
print "Player" + i + "Cards: " + Player i + "," + "total: " + tp
hitorstand = raw_input("hit (h) or stand (s)?")
if hitorstand == "h":
Player i.append(choice(cards))
print ("hit (h) or stand (s)?")
elif hitorstand == "s":
break
else print "Please enter h or s"
dealer = []
While True:
dealer.append(choice(cards))
dealer.append(choice(cards))
td = total(dealer)
while td > 17:
dealer.append(choice(cards))
else:
break
if td < tp < 21:
"Player i wins"
else print "dealer wins"
This is what I have so far. I understand there are lots of gibberish and code that won't work. I was wondering if you guys can let me know what is wrong with the code and maybe suggest some options on how to fix it.
My main concerns right now:
I am making a "multiplayer" blackjack game. I have no idea how I'm supposed to make a loop for a multiplayer blackjack game. In my code, I asked how many people are playing. How do I make a loop for the game without knowing what the number will be?
Also, how do I create a function to find out the winner without knowing how many players are playing?
After I type in
Players = raw_input("How many players are there?") for i in range Players:
The
Players
in the for loop gives me a syntax error. What is wrong?
As an update, I've thought about what you said about making a list and I still do not really understand how I should go about making a code to find out the winner.
for example
even if I make a list, if i do not know how many players are actually playing, I wouldn't be able to compare the elements in the list. If I knew how many people were playing,
playerlist = [1,2,3]
I can say
if playerlist[0] > playerlist[1], playerlist[2] and playerlist[0] < 21:
then print "player 1 wins!"
But since I won't know how many people are playing until the user actually types in the input, I am lost as to how I am supposed to write the code for the winner.
I do not know if there is a way of saying "if this is bigger than the rest". I only know how to say "if this is bigger than that".
Is there a way of saying "if this is bigger than the rest" in python? If not, can you give me some suggestions to making the code to find out the winner?