Distribution of Cards(List & Nested for)
We are going to create a program that will distribute 52 cards of a deck amongst 4 players "Randomly".
Distribution of Cards(List & Nested for)
import randomsuits = ['Hearts', 'Diamonds', 'Clubs', 'Spades']
ranks = ['Ace', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'Jack', 'Queen', 'King']
deck=[]
for suit in suits:
for rank in ranks:
deck.append((rank,suit))random.shuffle(deck)game=[]
for i in range(4):
l=[]
player=input(f'enter the name of {i} player:')
for card in deck[i::4]:
l.append(card)
l.insert(0,player)
game.append(l)
Last updated