Question

In: Computer Science

Write a function matchSuit() that simulates repeatedly drawing a pair of playing cards from a shuffled...

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.

Solutions

Expert Solution

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:


Related Solutions

Write a function called play_round that simulates two people drawing cards and comparing their values. High...
Write a function called play_round that simulates two people drawing cards and comparing their values. High card wins. In the case of a tie, draw more cards. Repeat until someone wins the round. the function has two parameters: the name of player 1 and the name of player 2. it returns a string with format ' wins!'. For instance, if the winning player is named Rocket, return 'Rocket wins!'. python
1. Five cards are dealt at random from a well-shuffled deck of 52 playing cards. Find...
1. Five cards are dealt at random from a well-shuffled deck of 52 playing cards. Find the probability that: a. All are spades. b. Exactly two are hearts. c. Exactly three are clubs. d. All are red. e. At least one card is ace. 2. Tossing a coin 15 times find the probability of getting exactly 4 tails. 3. Find the probability of getting at least 4 tails for tossing a coin 15 times
A 5-card hand is dealt from a perfectly shuffled deck of playing cards. What is the...
A 5-card hand is dealt from a perfectly shuffled deck of playing cards. What is the probability of each of the following events: a) The hand has at least one club b) The hand has at least two cards with the same rank c) The hand has exactly one club or exactly one spade d) The hand has at least one club or at least one spade
Assume that a standard deck of 52 playing cards is randomly shuffled (13 cards of 4...
Assume that a standard deck of 52 playing cards is randomly shuffled (13 cards of 4 types of suits - clubs, diamonds, hearts, and spades). If Alex draws a card from it 4 times with replacement, how many different combinations of suits can he get? (Suppose we further assume that the order doesn't matter: (clubs, diamonds, hearts, hearts) is equal to (hearts, clubs, diamonds, hearts). However, (clubs, diamonds, hearts, hearts) is different with (hearts, clubs, clubs, hearts).)
From shuffled deck of cards, 4 cards are randomly selected without replacement from shuffled deck of...
From shuffled deck of cards, 4 cards are randomly selected without replacement from shuffled deck of 52 cards. What is the probability to get at least one ace?
A game consists of drawing cards from a well shuffled 52-card deck without replacement until an...
A game consists of drawing cards from a well shuffled 52-card deck without replacement until an ace is not drawn. (a) What is the probability that you draw an ace on the first card? (b) What is the probability that you draw an ace on the fourth card? (c) What is the probability that you draw an ace on the fifth card? d) Suppose you have a bowl of 12 marbles, 6 of which are blue and the other 6...
With a standard deck of 52 playing cards, are your chances of drawing an ace and...
With a standard deck of 52 playing cards, are your chances of drawing an ace and then a king better with or without "replacement"? Illustrate with computations.
Write a class whose instances represent a single playing card from a deck of cards. Playing...
Write a class whose instances represent a single playing card from a deck of cards. Playing cards have two distinguishing properties: rank and suit. Use an enum type to represent rank and another enum type to represent suit. Write another class whose instances represent a full deck of cards. Both these classes should have toString methods. Write a small program to test your deck and card classes. The program can be as simple as creating a deck of cards and...
Consider a well shuffled deck of cards, from which 5 cards are drawn. a. Find the...
Consider a well shuffled deck of cards, from which 5 cards are drawn. a. Find the probability that you get three cards of hearts, and two cards of spades. b. Find the probability that you get three cards of the same suit, and two cards with the same suit (but different than the one of the three other cards).
draw 20 cards without replacement from a shuffled, standard deck of 52 cards. What is the...
draw 20 cards without replacement from a shuffled, standard deck of 52 cards. What is the conditional probability P (12th card and 20th card is a heart 3rd card is a club)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT