'''lecture_22_racquetball.py Build a terminal-based racquetball game simulation using top-down design Oliver W. Layton CS 151: Computational Thinking: Visual Media Fall 2020 Rules: - Players hit ball back and forth in the count. - Game starts by a player serving, like tennis. - Game played by players hitting ball back and forth (player A hits, then B, then A, then B...) Back and forth is called rally (like in Tennis). - The rally ends when one player fails to hit the ball during a rally - The point ends when the rally ends. - The loser the one who failed to hit ball back during the rally. - If the loser was the one who served, no points won or lost...the other serves now. - e.g. if B was serving and fails to hit ball, now A serves. - If the server wins, that player gets a point. - IMPORTANT: Game ends when one player gets 15 points. - Rule: Player A always starts serving Question: If player A and B played in a championship (many games) who would win? print('This program simulates a game of racquetball between two', 'players called A and B. The abilities of each player is', 'indicated by a probability (number between 0 and 1) that', 'the player wins the point when serving. Player A always', 'has the first serve.') ''' def printInstructions(): print('This program simulates a game of racquetball between two', 'players called A and B. The abilities of each player is', 'indicated by a probability (number between 0 and 1) that', 'the player wins the point when serving. Player A always', 'has the first serve.') def getUserInput(): probWinA = float(input('Please enter the prob Player A wins a point>>>')) probWinB = float(input('Please enter the prob Player B wins a point>>>')) nGames = int(input('How many games should we play?>>>')) return probWinA, probWinB, nGames def printResults(gamesAWon, gamesBWon): totalGames = gamesAWon + gamesBWon print('Player A won', gamesAWon, 'games (', 100*gamesAWon/totalGames, 'percent)') print('Player B won', gamesBWon, 'games (', 100*gamesBWon/totalGames, 'percent)') def main(): # pseudo code: English words describing what to do to solve the problem # 1. Print out instructions about what this program does and what to enter # DONE! printInstructions() # 2. Get user input: need to know (probability that player A wins point), (prob player B wins point) # how many games we are playing. # DONE! probWinA, probWinB, nGames = getUserInput() # 3. Simulate the games gamesAWon, gamesBWon = simulateNGames(probWinA, probWinB, nGames) # 4. Print out the results: how many games player A and player B won the championship # DONE! printResults(gamesAWon, gamesBWon) if __name__ == '__main__': main()