Question

In: Computer Science

Python: Write a program that keeps track of a game score and declares the winner when...

Python:

Write a program that keeps track of a game score and declares the winner when the game is over. A game is over when either one player scores 10 or more points with at least 2 more points than the opponent. A game is also over when one player scores 7 points and the opponent scores none. The program should begin by asking the names of the two players. Then, it should keep asking who won the point till the game is over (you will need to prompt user to determine who won the point. In the end it should display the winner and the final score.

Solutions

Expert Solution

Dear student,

The game designed using Python programming language as stated above is as follows:

CODE:



print("Welcome to the GAME\n")
player1=input("Please enter your name: ")
player2=input("Please enter the name of your opponent: ")
players={1:player1,2:player2}

point1=0   #score of player1
point2=0  #score of player2

winner=0  #stores who is the winner

#Now a loop runs till one player wins

while(True):
    print("Enter 1 to choose ",player1)
    print("Enter 2 to choose ",player2)
    point=int(input("Who won the point this round: "))
    
    if(point==1):
        point1=point1+1
        if(point1>=10):
            if(point1-point2>=2):
                winner=1;
                break;
        if(point1==7 and point2==0):
            winner=1;
            break;
    if(point==2):
        point2=point2+1
        if(point2>=10):
            if(point2-point1>=2):
                winner=2;
                break;
        if(point2==7 and point1==0):
            winner=2;
            break;
        
    
#Loop has ended

if(winner==1):
    print("Winner is ",player1)
if(winner==2):
    print("Winner is ",player2)
    


print("\nFinal Scores are:\n")
print(player1,": ",point1)
print(player2,": ",point2)
  

-----------------------------------------------------------------------------------------------------------------------------------------------------

SAMPLE OUTPUTS:

OUTPUT 1:

Welcome to the GAME

Please enter your name: Tim
Please enter the name of your opponent: John
Enter 1 to choose Tim
Enter 2 to choose John
Who won the point this round: 1
Enter 1 to choose Tim
Enter 2 to choose John
Who won the point this round: 2
Enter 1 to choose Tim
Enter 2 to choose John
Who won the point this round: 2
Enter 1 to choose Tim
Enter 2 to choose John
Who won the point this round: 2
Enter 1 to choose Tim
Enter 2 to choose John
Who won the point this round: 2
Enter 1 to choose Tim
Enter 2 to choose John
Who won the point this round: 2
Enter 1 to choose Tim
Enter 2 to choose John
Who won the point this round: 1
Enter 1 to choose Tim
Enter 2 to choose John
Who won the point this round: 1
Enter 1 to choose Tim
Enter 2 to choose John
Who won the point this round: 1
Enter 1 to choose Tim
Enter 2 to choose John
Who won the point this round: 1
Enter 1 to choose Tim
Enter 2 to choose John
Who won the point this round: 1
Enter 1 to choose Tim
Enter 2 to choose John
Who won the point this round: 2
Enter 1 to choose Tim
Enter 2 to choose John
Who won the point this round: 2
Enter 1 to choose Tim
Enter 2 to choose John
Who won the point this round: 2
Enter 1 to choose Tim
Enter 2 to choose John
Who won the point this round: 2
Enter 1 to choose Tim
Enter 2 to choose John
Who won the point this round: 1
Enter 1 to choose Tim
Enter 2 to choose John
Who won the point this round: 1
Enter 1 to choose Tim
Enter 2 to choose John
Who won the point this round: 1
Enter 1 to choose Tim
Enter 2 to choose John
Who won the point this round: 1
Enter 1 to choose Tim
Enter 2 to choose John
Who won the point this round: 1
Winner is Tim

Final Scores are:

Tim : 11
John : 9

OUTPUT 2:

-----------------------------------------------------------------------------------------------------------------------------------------------------

I hope the given solution helps clear your doubt.

Don't forget to give it a thumbs up.

Regards


Related Solutions

Using Python 3, Write a class called GolfScore that keeps track of the score for a...
Using Python 3, Write a class called GolfScore that keeps track of the score for a person playing a round of golf. We will limit the round to 9 holes, just to make testing easier. As a reminder, the holes on the golf course are numbered 1 – 9. Create a class level variable named NUM_OF_HOLES set to 9. Methods to be written: The constructor – sets the score for all holes to -1 addScore (hole, score) – this method...
create a program that asks user math questions and keeps track of answers... Python Allow the...
create a program that asks user math questions and keeps track of answers... Python Allow the user to decide whether or not to keep playing after each math challenge. Ensure the user’s answer to each math problem is greater than or equal to zero. Keep track of how many math problems have been asked and how many have been answered correctly. When finished, inform the user how they did by displaying the total number of math problems, the number they...
Write a C++ program for Euclids Algorithm that keeps track of the number of iterations (%...
Write a C++ program for Euclids Algorithm that keeps track of the number of iterations (% & loop) 1. Euclid’s Algorithm An alternative of the Euclidean algorithm for finding greatest common divisors (GCD) is repeatedly performing the modulo operation on two numbers until the remainder is 0. Here is the pseudocode for find the GCD of two positive numbers a and b using the Euclidean algorithm :while b ≠ 0 temp = b b = a mod t a =...
Hello! Working with python This program asks user math questions and keeps track of answers... Allow...
Hello! Working with python This program asks user math questions and keeps track of answers... Allow the user to decide whether or not to keep playing after each math challenge. Ensure the user’s answer to each math problem is greater than or equal to zero. Keep track of how many math problems have been asked and how many have been answered correctly. When finished, inform the user how they did by displaying the total number of math problems, the number...
Grocery List Program Write a program that keeps track of the user's grocery list items. Prompt...
Grocery List Program Write a program that keeps track of the user's grocery list items. Prompt the user if they'd like to (each action is a function): See the list Display all items (if any) in the list Add item to their list Confirm with the user before adding item (y/n or yes/no) If they enter a duplicate item, notify them the item already exists Remove items from their list Confirm with the user before removing item (y/n or yes/no)...
Write a program in Python to simulate a Craps game: 1. When you bet on the...
Write a program in Python to simulate a Craps game: 1. When you bet on the Pass Line, you win (double your money) if the FIRST roll (a pair of dice) is a 7 or 11, you lose if it is ”craps” (2, 3, or 12). Otherwise, if it is x ∈ {4, 5, 6, 8, 9, 10}, then your point x is established, and you win when that number is rolled again before ’7’ comes up. The game is...
Write a program IN PYTHON of the JUPYTER NOOTBOOK that keeps getting a set of numbers...
Write a program IN PYTHON of the JUPYTER NOOTBOOK that keeps getting a set of numbers from user until the user enters "done". Then shows the count, total, and average of the entered numbers. This should the answer when finished Enter a number: 55 Enter a number: 90 Enter a number: 12 Enter a number: done You entered 3 numbers, total is 157, average is 52.33333
Write C++ a program that shows a class called gamma that keeps track of how many...
Write C++ a program that shows a class called gamma that keeps track of how many objects of itself there are. Each gamma object has its own identification called ID. The ID number is set equal to total of current gamma objects when an object is created. Test you class by using the main function below. int main()    {    gamma g1;    gamma::showtotal();    gamma g2, g3;    gamma::showtotal();    g1.showid();    g2.showid();    g3.showid();    cout <<...
Write a python program that simulates a simple dice gambling game. The game is played as...
Write a python program that simulates a simple dice gambling game. The game is played as follows: Roll a six sided die. If you roll a 1, 2 or a 3, the game is over. If you roll a 4, 5, or 6, you win that many dollars ($4, $5, or $6), and then roll again. With each additional roll, you have the chance to win more money, or you might roll a game-ending 1, 2, or 3, at which...
Write a python program that keeps names and email addresses in a dictionary as key-value pairs....
Write a python program that keeps names and email addresses in a dictionary as key-value pairs. The program should display a menu that lets the user look up a person’s email address, add a new name and email address, change an existing email address, and delete an existing name and email address. The program should bind the dictionary and save it to a file when the user exits the program. Each time the program starts, it should retrieve the dictionary...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT