I’m new to python and I’m programming the Blackjack game in python with a friend of mine. I’m getting Keyerror:0 on this lines:
card1=random.choice(cards)
card2=random.choice(cards)
Is it a writing mistake or something bigger? Please help me
For context, here’s the part of the code with those lines, ngiocatori is the number of players and its input is before in the code:
pgiocatori=1
cards={
1: "A",
2: "2",
3: "3",
4: "4",
5: "5",
6: "6",
7: "7",
8: "8",
9: "9",
10: ["10", "J", "Q", "K"],
11: "A"
}
card1=random.choice(cards)
card2=random.choice(cards)
def give_cards():
print(f"Le carte del giocatore {pgiocatori} sono: " + str(carta1) +"; " + str(carta2))
while pgiocatori<=ngiocatori:
give_cards()
pgiocatori+=1
card1=random.choice(cards)
card2=random.choice(cards)```
New contributor
Leobac2009 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.