Card game theory
Ok, let's get back to our unfinished card game. We had this pack of cards created with a list comprehension method, right? PS: we're using Jupyter for this... in case you're asking...In [3]:cards = [str(num)+color for num in range(1,11) for color in ['♥','♦','♣','♠']] x = 0 for c in cards: print(c,end=' ') x +=1 if x==10: x = 0 print()
Now wi shuffle the cards... and pop() three of them
In [6]:
from random import shuffle
shuffle(cards)
def pop(cardnum):
'pc1 = pop(3) # it gives a list of 3 cards as result'
cardlist = []
for i in range(cardnum):
cardlist += [cards.pop()]
return cardlist
pc1 = []
pc1 = pop(3)
print(pc1)
Comments
Post a Comment