Python Edit the racquetball game so that all user input is validated # rball.pyfrom random import randomdef main(): printIntro() probA, probB, n = getInputs() winsA, winsB = simNGames(n, probA, probB)...



Python



Edit the racquetball game so that all user input is validated


# rball.pyfrom random import randomdef main(): printIntro() probA, probB, n = getInputs() winsA, winsB = simNGames(n, probA, probB) printSummary(winsA, winsB)def printIntro(): print("This program simulates a game of racquetball between two") print('players called "A" and "B". The abilities of each player is') print("indicated by a probability (a number between 0 and 1) that") print("the player wins the point when serving. Player A always") print("has the first serve.")def getInputs(): # Returns the three simulation parameters, the prob. that either player wins a serve should be in-between 0 and 1 a = eval(input("What is the prob. player A wins a serve? ")) b = eval(input("What is the prob. player B wins a serve? ")) n = eval(input("How many games to simulate? "))#the number of games should be an integer return a, b, ndef simNGames(n, probA, probB): # Simulates n games of racquetball between players whose # abilities are represented by the probability of winning a serve. # Returns number of wins for A and B winsA = winsB = 0 for i in range(n): scoreA, scoreB = simOneGame(probA, probB) if scoreA > scoreB: winsA = winsA + 1 else: winsB = winsB + 1 return winsA, winsBdef simOneGame(probA, probB): # Simulates a single game or racquetball between players whose # abilities are represented by the probability of winning a serve. # Returns final scores for A and B serving = "A" scoreA = 0 scoreB = 0 while not gameOver(scoreA, scoreB): if serving == "A": if random() < proba:="" scorea="scoreA" +="" 1="" else:="" serving="B" else:="" if="" random()="">< probb:="" scoreb="scoreB" +="" 1="" else:="" serving="A" return="" scorea,="" scorebdef="" gameover(a,="">

Jun 08, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here