python tennis scoreboard
Need some help with a year end tennis program assignment:
In this problem you will provide an interface and display for a tennis match. Here are the rules for scoring a tennis match.
• There are two players. Let’s call them Player 1 and Player 2.
• Players rally the ball back and forth, and the winner of each rally earns a point.
• A game is a sequence of several points. Each player starts with 0 points (Love all), and the gam is won by the player who achieves the following first:
– the player has 4 points; and – the player has 2 more points than the other player.• The British have a clever numbering system for points within a game.
A player with 0 points has “Love”. If they have 1 point, they call it “15”. 2 points is “30”; 3 points, “40”. If both players are tied at 3 points or more, they call it “Deuce”.If both players have 3 or more points, but they are not tied, then the player that’s ahead is said to have the “Advantage”.
• A set is a sequence of games.
The winner of the set is the first player to reach: 6 games with at least 2 more games than the other player; or – 7 games.In the case where both players are tied at 6 games apiece, the rules change for how the 13th and deciding game are scored. This game is called the tiebreak, and it is won by the first player to accumulate 7 points with 2 more points than the other player. In a tiebreak, the British numbering is not used; instead the score starts at 0-0, and points are counted in an increasing numerical sequence.
• A match is a sequence of sets. In men’s events, the winner of the match is the first player to reach 3 sets. In women’s, the winner is the first player to reach 2 sets.
Complete the function points_str(p1, p2) which, given p1, the number of points for Player 1, and p2, the number of points for Player 2, returns a string that represents the British equivalent of Player 1’s score. If Player 1 has the advantage, return "Adv", while if Player 2 has the advantage, return "-".
For examples,
• points_str(0, 2) should return "Love". • points_str(3, 1) should return "40". • points_str(3, 3) should return "Deuce". • points_str(5, 4) should return "Adv". • points_str(4, 5) should return "-".Write a Python program that simulates a tennis match. After asking the user for the names of each player and their sex, the program will display the scoreboard after each point is played.
To determine who wins the next point, your program will call the imported function umpire() which returns the integer 1 if Player 1 wins the point or 2 if Player 2 wins. You may assume that umpire() never returns anything except the integer 1 or the integer 2.
The program should end when either player wins the match. Output the final scoreboard, and a message describing who wins. Follow the output format as shown in the samples.
Below is my code so far for the function. It only calculates the winner of the first point and displays it. How do i loop it properly so it calculates the winner of the game, set, and match eventually?
Please help me out :) Thanks!
def points_str(p1, p2):
p1setscore=0
p2setscore=0 # setting starting parameters for scorekeeping for games and
p1gamescore=0
p2gamescore=0
male_setmax=3
female_setmax=2 # setting parameters for maximum amount sets/games for male/female rules
gamemax=7
umpire()
if umpire()== 1:
p1gamescore=p1gamescore+1
else:
p2gamescore=p2gamescore+1
print p1gamescore,开发者_如何转开发 p2gamescore
Write a function that returns if someone (optionally who) wins, and another function that tests the players' scores and returns the score situation string. Loop through calling umpire()
, accumulating the points, and getting and outputting the situation until someone wins (hint: while not winnerfunc(...):
).
Think of it in terms of a states. There are six states:
- normal (score [0123]-[0123], except 3-3)
- deuce round (score 3-3)
- player 1 winning (score 4-[012] or score 5-3)
- player 2 winning (score [012]-4 or score 3-5)
- deuce player 1 advantage (score 4-3)
- deuce player 2 advantage (score 3-4)
精彩评论