Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Inital preparations In PyCharm or Eclipse, create a new project with the name assignment10_1. In this project, create a module tennis. Description of the exercise

Inital preparations

In PyCharm or Eclipse, create a new project with the name "assignment10_1". In this project, create a module tennis.

Description of the exercise

In module tennis, write a program which can be used to calculate the point scores of one tennis game. Note that the word "game" in tennis does not mean the whole match, but is just a small part of it. A detailed description about calculating the point scores is given below.

Background: calculating point scores

A tennis match consists of 2-5 sets. Each set consists of several games. Usually the player who wins six games first wins the set. However, there are exceptions to this in the case the difference in the number of games won is not large enough (they will not be dealt with more specifically here as they are not needed for this exercise).

In this exercise you have to implement a program which calculates the point scores of a single game. Please note that the game is only part of one set and does not mean the whole match. During the game, the same player is always serving. The players try to win points. The score of the winner of one point is 15, the score of the winner of two points is 30, and the score of the winner of three points is 40. If the player's score is 40 and the competitor's score is smaller, the player wins the game if he/she wins the next point.

However, if both players have score 40, the situation is more complicated. To win the game, the player has to get an advantage. If the score is 40-40, either the player who wins the point gets the advance OR the player who loses the points loses the advance (but never the both happening at the same time) as follows:

  • If the score is 40-40 deuce (neither player has an advantage), the winner of the point gets an advantage, but the score remains 40-40.
  • If the score is 40-40 and the winner of the point has an advantage, the winner wins the game. The game ends.
  • If the score is 40-40 and the loser of the point has an advantage, the score remains the same, but neither of the players has an advantage. The game is 40-40 deuce. (In practice, this means that the player has to win two consecutive points to win the game.)

When moving from score 40-30 (or 30-40) to score 40-40, the score is tied (i.e. deuce) and the winner of the next point gets an advantage.

More information is available in page https://en.wikipedia.org/wiki/Tennis_scoring_system. You can also inspect the examples below to see how the playes get or lose the advantage.

Execution of the program

At first, the program asks the user to enter the names of the player serving and his / her competitor. After that, the program repeats asking which player has won the point until one of the players wins the game.

The program outputs the score (the serving player first) after each point as long as the game has not been finished. If both players have score 40, the program also outputs whether the serving player has an advantage (advantage in), or the competitor has an advantage (advantage out) or the game is tied (deuce).

When the game finishes, the program outputs that the game ended and outputs the name of the winner. The program does not output the score at this point.

See the examples below to see the exact output in each situation.

Error handling

If the user enters another number than 1 or 2 when asked for the winner of a point, the program informs about invalid number, but outpust the score as normally and continues buy asking for the number of the winner of the next point. You may assume that the use always enters an integer and not any other type of input.

Structure of the program

You do not have to split your program to several functions. You are allowed write all code in the main function. However, you are allowed to define also other functions, if you want.

Output formatting

Check that the output of your program is similar to the examples given below.

Examples of the execution of the program:

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Unity From Zero To Proficiency Beginner A Step By Step Guide To Coding Your First Game

Authors: Patrick Felicia

1st Edition

1091872023, 978-1091872028

More Books

Students also viewed these Programming questions