Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The pans deck has one i, too 2°, tkvee 3 ten \'sPis u OY 55 cards nitiolly the d

ID: 3724804 • Letter: T

Question

The pans deck has one i, too 2°, tkvee 3 ten 'sPis u OY 55 cards nitiolly the deck i srandemiaed and two cands ane m.lsume player A qets the lowex cand & player 8 ges uppex the too cards draun Rounds begin Arom belouFor one game) The player A with the lovex cand oes nst and drouws a B then ployer A,., wilill ene of them a pair dnd that p laye with a paise loases Please add detailed comments and output urite a program in Python 3 tor to,000 games what Pidetion A wins (ey when Bgets toack pained and loase) aclion B wins Cive, when ooses the average of how mony seunds one played

Explanation / Answer

Comments and output are detailed. If you are satisfied, kindly rate the answer positive :)

If not, please specify in the comment. I would be happy to rectify anything

Code is as follows

import random
from fractions import Fraction

gameno = 0; Awin = 0; Bwin = 0; TotalRounds = 0;
while gameno != 10000:
gameno += 1
print("Simulating Game ", gameno)
cards = []
for i in range(1, 10):
    cards += [str(i)] * i

print("Shuffling the cards")
random.shuffle(cards)

A = []; B = []
while 1:
    TotalRounds += 1
    print("Two cards drawn")

    a = random.randrange(len(cards))
    print("A draws ", cards[a])
    A += cards.pop(a)

    #a set can be used to remove duplicates
    #if size isnt same implies that duplicates were found
    if len(A) != len(set(A)):
      Bwin += 1; print("A loses!"); break;
  
    b = random.randrange(len(cards))
    print("B draws ", cards[b])

    B += cards.pop(b)
  
    #a set can be used to remove duplicates
    #if size isnt same implies that duplicates were found
    if len(B) != len(set(B)):
      Awin += 1; print("B loses!"); break;
print(" ")

A = Fraction(Awin, gameno)
B = Fraction(Bwin, gameno)
AvgRound = Fraction(TotalRounds, gameno)

print("Fraction A won ", A)
print("Fraction B won ", B)
print("Average rounds ", AvgRound)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote