having an issue in regards to writing a program that can simulate the number of picks from a deck of cards needed before getting one of each suit. I run into an infinite loop, and I'm not sure how to get out of it and get my required output.
import random
def coupon_collector():
suits=['Hearts','Diamonds','Spades','Clubs']
cards=['Ace','2','3','4','5','6','7','8','9','10','Jack','Queen','King']
def has_suit(cards,suit):
for s in cards:
if suit == s:
return True
return False
def has_all_suits(cards):
for suit in suits:
if not has_suit(cards,suit):
return False
return True
def main():
deck=[]
my_cards=[]
j=0
for i in range(52):
deck.append(suits[i%4]+cards[int(i/4)])
while not has_all_suits(my_cards):
ind=random.randint(0,51)
card=deck[ind]
if not has_suit(my_cards,card[0]):
my_cards.append(card)
j+=1
for card in my_cards:
print(card[1],'of',card[0])
print('Number of picks:',j)
main()
coupon_collector()