I'm making a card game in python, and having trouble dealing the cards out to players (for simplification, cards are just strings, where AH is ace of hearts). I'm trying to deal one card to each player in turn using modulo. However, for each iteration of the for loop every player is getting the same card, not just one player. I don't understand why - if anyone could help I'd be v appreciative!
class Player:
def __init__(self, hand = []):
self.hand = hand
deck = ["AS", "2S", "3S", "4S", "5S", "6S", "7S", "8S", "9S", "10S", "JS", "QS", "KS",
"AH", "2H", "3H", "4H", "5H", "6H", "7H", "8H", "9H", "10H", "JH", "QH", "KH",
"AC", "2C", "3C", "4C", "5C", "6C", "7C", "8C", "9C", "10C", "JC", "QC", "KC",
"AD", "2D", "3D", "4D", "5D", "6D", "7D", "8D", "9D", "10D", "JD", "QD", "KD"]
player1 = Player()
player2 = Player()
player3 = Player()
players = [player1, player2, player3]
def dealCards(deck, players):
for i in range(len(deck)):
j = i % len(players)
players[j].hand.append(deck[i])
calculateHandSize(deck, players)