Managing a tennis score
jodu4200
Posted messages
11
Status
Member
-
Anonymous user -
Anonymous user -
Hello everyone, I have an oral exam in two weeks and I have a big problem: I need to implement the following project: manage the score of a tennis match.
Tip: 1- Under what condition does a player win a game?
2- Define a function that counts the points during a game. The program should stop as soon as a player wins the game, after displaying the name of the winner.
3- Write a second function that counts the games within a set and stops when a player wins the set. this function should call the previous one to know who wins the games. Don’t forget to plan for the tiebreak game.
4- Write a third function that counts the sets and stops when a player wins the match. Before starting the match, you can ask how many sets are needed to win.
so here is what I did:
i wrote the function that counts the points but afterwards I can't write the function for the game and I don't know how to link the game function to the point function
EDIT : Added code tags
Please kindly use syntax highlighting (code tags) when you post code on the forum.
Explanations available here :
https://codes-sources.commentcamarche.net/faq/10686-le-nouveau-codes-sources-comment-ca-marche#balises-code
Tip: 1- Under what condition does a player win a game?
2- Define a function that counts the points during a game. The program should stop as soon as a player wins the game, after displaying the name of the winner.
3- Write a second function that counts the games within a set and stops when a player wins the set. this function should call the previous one to know who wins the games. Don’t forget to plan for the tiebreak game.
4- Write a third function that counts the sets and stops when a player wins the match. Before starting the match, you can ask how many sets are needed to win.
so here is what I did:
def point(): nadal=1 federer=2 score=[0,15,30,40,"jeu"] ex=[40,"adv","jeu"] score1=score[0] score2=score[0] j1=0 j2=0 while score1!="jeu" and score2!="jeu": vainqueur=input("qui a marque?") if score1==40 and score2==40: if vainqueur=="1": score1="adv" else: score2="adv" elif score1==40 and score2=="adv": if vainqueur=="2": score1=40 score2="jeu" elif vainqueur=="1": score1=40 score2=40 elif score1=="adv" and score2==40 : if vainqueur=="1": score1="jeu" score2=40 elif vainqueur=="2": score1=40 score2=40 elif vainqueur=="1": j1=j1+1 score1=score[j1] else: j2=j2+1 score2=score[j2] print(score1,score2) print(score1,score2) i wrote the function that counts the points but afterwards I can't write the function for the game and I don't know how to link the game function to the point function
EDIT : Added code tags
Please kindly use syntax highlighting (code tags) when you post code on the forum.
Explanations available here :
https://codes-sources.commentcamarche.net/faq/10686-le-nouveau-codes-sources-comment-ca-marche#balises-code
1 answer
-
-
Hi there! Here is the natural French-to-English translation of the entire text you shared: Hi, actually here’s what the professor says we should do: 1) For now, I suggest we simplify the tennis match: only one set, no tiebreak. 2) Separate the display from the program logic. This is always very important. Could you display the score as follows (for example): Set Jeu Nadal 2 15 Federer 1 30 This score display will be entrusted to a function "DisplayScore()" (no parameters, no return value). Each time a point is scored, we call this function. 3) What data do we need to display the score above? - For the set, the score can be 6-4 or 5-7 but also 10-8 or 13-11 (noting that the record is 70-68 on 24/06/2010 at Wimbledon between Isner and Mahut!). - For the game, logically it’s also straightforward: we only need successive numbers 0, 1, 2, 3, 4, 5, 6, 7, 8, ... The winner of the game is the first to reach 4 points or more with at least 2 points more than the opponent. From an display perspective... if 0 we display 0, if 1 we display 15, etc... but that’s the display issue! - This data will be global data, stored in global variables. Do you understand the concept of global variables (declared in the main program) and local variables (declared inside a function)? 4) I propose the algorithm below for the main loop (you’re allowed to change the variable names if you want). There you go, that’s all. Tell me if my answer helped you. Don’t hesitate to contact me again. Happy development, Yann Beauquis Algorithm proposed for the main loop: BEGIN While (not end of match) Do # call of the function "DisplayScore()" DisplayScore() # call of the function "PlayPoint()" # prompt the user to enter the winner of the point (1 or 2) # return value: 1 or 2 winnerPoint = PlayPoint() # call of the function "Game(winnerPoint)" : # Parameter: # winnerPoint: the winner of the point (1 or 2) # Return value: 1 if Nadal wins the game, or 2 if Federer wins, or 0 if the game continues # Description: # Increment by 1 the game of the point winner # If (game won) then # display "game" for the winning player (e.g. "game Federer" or "game player 2") # reset the game score to zero (for the next game) # return = the winner of the game # Else # return = 0 gameWinner = Game(point) # call of the function "Set(winnerGame)" if game is 1 or 2: # Parameter: # winnerGame: the winner of the game (1 or 2) # Return value: 1 Nadal wins the set, or 2 Federer wins, or 0 if the set continues # Description: # Increment by 1 the set of the game winner # If (set won) then # display "set" for the winning player (e.g. "set Federer" or "set player 2") # return = the winner of the set # Else # return = 0 If (gameWinner == 1 or 2) then winnerSet = Set(gameWinner) Finsi End While END If you could help me with this, that would be awesome, considering I have two weeks left :( (Note: I kept the original structure and wording, translating into fluent English while preserving the technical content and the requested formatting. If you’d prefer a version in French or a concise summary, tell me.)
-
-
-
-
-