loops - python tennis scoreboard -
need year end tennis program assignment:
in problem provide interface , display tennis match. here rules scoring tennis match.
• there 2 players. let’s call them player 1 , player 2.
• players rally ball , forth, , winner of each rally earns point.
• game sequence of several points. each player starts 0 points (love all), , gam won player achieves following first:
– player has 4 points; and
– player has 2 more points other player.
• british have clever numbering system points within game.
player 0 points has “love”. if have 1 point, call “15”. 2 points “30”; 3 points, “40”. if both players tied @ 3 points or more, call “deuce”.
if both players have 3 or more points, not tied, player that’s ahead said have “advantage”.
• set sequence of games.
winner of set first player reach:
6 games @ least 2 more games other player; or
– 7 games.
in case both players tied @ 6 games apiece, rules change how 13th , deciding game scored. game called tiebreak, , won first player accumulate 7 points 2 more points other player. in tiebreak, british numbering not used; instead score starts @ 0-0, , points counted in increasing numerical sequence.
• match sequence of sets. in men’s events, winner of match first player reach 3 sets. in women’s, winner first player reach 2 sets.
complete function points_str(p1, p2) which, given p1, number of points player 1, , p2, number of points player 2, returns string represents british equivalent of player 1’s score. if player 1 has advantage, return "adv", while if player 2 has 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 python program simulates tennis match. after asking user names of each player , sex, program display scoreboard after each point played.
to determine wins next point, program call imported function umpire() returns integer 1 if player 1 wins point or 2 if player 2 wins. may assume umpire() never returns except integer 1 or integer 2.
the program should end when either player wins match. output final scoreboard, , message describing wins. follow output format shown in samples.
below code far function. calculates winner of first point , displays it. how loop calculates winner of game, set, , match eventually?
please me out :) thanks!
def points_str(p1, p2): p1setscore=0 p2setscore=0 # setting starting parameters scorekeeping games , p1gamescore=0 p2gamescore=0 male_setmax=3 female_setmax=2 # setting parameters maximum amount sets/games male/female rules gamemax=7 umpire() if umpire()== 1: p1gamescore=p1gamescore+1 else: p2gamescore=p2gamescore+1 print p1gamescore, p2gamescore
write function returns if (optionally who) wins, , function tests players' scores , returns score situation string. loop through calling umpire(), accumulating points, , getting , outputting situation until wins (hint: while not winnerfunc(...):).
Comments
Post a Comment