In: Computer Science
Write a function matchSuit() that simulates repeatedly drawing a pair of playing cards from a shuffled deck (of 52 cards) until the pair of cards share the same suit (or you run out of cards). The function should return the total number of cards drawn. Use a while loop. To draw each card, call the drawCard function you wrote above.
Here i wrote a code which is asked me to do here draw card function will randomly choose the card form the remaining deck we provided. the whole function/program is written in python and there is associated output file also.
Hope this answer would help you please vote
CODE:
def drawcard(deck):
card = random.choice(deck)
deck.remove(card)
return card
def matchsuit():
deck=['Ac','2c','3c','4c','5c','6c','7c','8c','9c','Tc','Jc','Qc','Kc','As','2s','3s','4s','5s','6s','7s','8s','9s','Ts','Js','Qs','Ks','Ah','2h','3h','4h','5h','6h','7h','8h','9h','Th','Jh','Qh','Kh','Ad','2d','3d','4d','5d','6d','7d','8d','9d','Td','Jd','Qd','Kd']
count=0
while (count<52):
if drawcard(deck)[1]==drawcard(deck)[1]:
count+=2
print("the number of card drawn",count)
return
count+=2
for i in range(11):
print(i+1," run")
matchsuit()
OUTPUT: