Part II: Deal the Cards (10 points) Complete the function deal-cards ), which ta
ID: 3718114 • Letter: P
Question
Part II: Deal the Cards (10 points) Complete the function deal-cards ), which takes one argument, deck, is a list Cards objects (but not necessarily exactly 52 cards). The objects in deck might appear in any random (shuffled) order. The function creates and returns (as a tuple) two Player objects with the following values: . -player num: 1 or 2, as appropriate . score: 0 cards: the empty list The function appends alternating Card objects from deck to the cards attribute of each Player object. More specifically, 1. Player 1 receives the Card object at deck [0]. 2. Player 2 receives the Card object at deck [1. 3. Player 1 receives the Card object at deck [2. 4. Player 2 receives the Card object at deck [3]. and so on, for all the cards in deck.Explanation / Answer
def deal_cards(deck):
list1 = []
p1 = Player(1,0, list1)
list2 = []
p2 = Player(2,0, list2)
for i in range(len(deck)):
if i % 2 == 0:
p1._cards.append(deck[i])
else:
p2._cards.append(deck[i])
tuple1 = (p1,p2)
return tuple1