Question

In: Computer Science

PYTHON The game of Morra is a hand game that dates back to ancient Greece and...

PYTHON

The game of Morra is a hand game that dates back to ancient Greece and Rome. In the real game, any number of players can play, but for this question we will assume two players only. The game is played in rounds. Each round, both players throw out one hand showing between 0 and 5 fingers and simultaneously call out what they think the sum of the fingers on the hands of all players will be. Any player who guesses correctly gets a point. The first player to 3 points wins. You will write a program that simulates a two-player game of Morra. Your program must do the following for each round of play until the game is over: • At the beginning of each round, print out the round number. The first round is round 1. • Read from the console the number of fingers shown by player 1, the number of fingers shown by player 2, player 1’s guess at the sum, and player 2’s guess at the sum. • Print to the console whether any players made a correct guess, and if so, that player’s new point total. If neither player guessed correctly, print a message indicating this. Note that BOTH players might guess correctly, in which case they both earn a point! Once the game is over, print the final outcome of the game. There are a few possibilities: • Print Player X wins! where X is either 1 or 2 depending on which player won. • If, however, the winning player won by a score of 3 to 0, instead print Player X wins a glorious victory!, again where X is either 1 or 2 as appropriate. • It is possible that the game is a tie. For example, if the score is 2 to 2, and both players guess correctly in the next round, both players will have three points when the game ends. In such a case, instead of printing either of the above messages, print It’s a tie!.

(a) Remember: you don’t have to generate player moves randomly. You are reading them from the console each round. Think of your program as the referee — it asks for the players moves each round using console input, then reports on the outcome of each round using console output, and finally prints the outcome of the game. (b) Your program only has to play one full game. To referee another game, run the program again! (c) You may assume that the user enters only valid data. That is, you do not have to actually check whether player moves are between 0 and 5 and that their guesses are between 0 and 10. Just assume that valid values are always entered.

Solutions

Expert Solution

Hi,

Hope you are doing fine. I have coded the above question in python and made sure that all the conditions mentioned in the questions are met. The code is clearly explained using comments which have been highlighted in bold. Even the assumptions made in the question are taken to be true about the input and valid entries.

Program:

#round_num stores the round number
round_num=0
#p1_points stores the points of player 1
p1_points=0
#p2_points stores the points of player 2
p2_points=0

#this loop is executed as long as p1_points and p1_points are not equal to 3. It break when either of them is 3
while(p1_points!=3 and p2_points!=3):
  
#Incrementing the round_num at the start of each iteration
round_num+=1

#printing round number
print("Round {}".format(round_num))
  
#Taking inputs from user and converting them into integer.
p1_num=int(input("Enter the number of fingers shown by player 1: "))

p2_num=int(input("Enter the number of fingers shown by player 2: "))

p1_guess=int(input("Enter the player 1's guess at sum: "))

p2_guess=int(input("Enter the player 2's guess at sum: "))
  
#if both players guess the sum correctly
if p1_num+p2_num==p1_guess and p1_num+p2_num==p2_guess:
#We increase the points of both players and print out their new points
p1_points+=1
p2_points+=1
print("Both player 1 and player 2 made a correct guess!")
print("Player 1 new points: {}".format(p1_points))
print("Player 2 new points: {}".format(p2_points))
#if player 1 guesses the sum correctly
elif p1_num+p2_num==p1_guess:
#We increase the points of player 1 and print out his new points
p1_points+=1
print("Player 1 made a correct guess!")
print("Player 1 new points: {}".format(p1_points))
#if player 2 guesses the sum correctly
elif p1_num+p2_num==p2_guess:
#We increase the points of player 2 and print out his new points
p2_points+=1
print("Player 2 made a correct guess!")
print("Player 2 new points: {}".format(p2_points))
#if both the players do not guess correctly
else:
print("Neither of the players made a correct guess.")
print("")

#if player 1 wins over player 2 with a score of 3-0
if (p1_points==3 and p2_points==0):
print('\nPlayer 1 wins a glorious victory!')
  
#if player 2 wins over player 1 with a score of 3-0
elif (p1_points==0 and p2_points==3):
print('\nPlayer 2 wins a glorious victory!')
  
#if both players have same points
elif p1_points==p2_points:
print("\nIt’s a tie!")
  
#if player 1 points are 3
elif (p1_points==3):
print('\nPlayer 1 wins the game!')
  
#if player 2 points are 3
else:
print('\nPlayer 2 wins the game!')
print('Player 1 points: {}'.format(p1_points))
print('Player 2 points: {}'.format(p2_points))

Executable code snippet of the program from jupyter notebook:

Output:


Related Solutions

why is important in today's day to do a research paper proposal on ancient Egypt and ancient Greece?
1. why is important to know the similarities and differences between Ancient Egypt and Ancient Greece.   2. why is important in today's day to do a research paper proposal on ancient Egypt and ancient Greece?
In Ancient Rome vs. Ancient Greece. Please choose one aspect of their respective art and describe...
In Ancient Rome vs. Ancient Greece. Please choose one aspect of their respective art and describe how they differ from one another in style. What does this say about each of the societies?
Euthyphro presents himself as an authority about the gods of ancient Greece. Group of answer choices...
Euthyphro presents himself as an authority about the gods of ancient Greece. Group of answer choices True False Flag this Question Question 4 10 pts Socrates finds that Euthyphro knows what he is talking about in ethics and the debate ends quickly with both of them in agreement. Group of answer choices true or false
Assessment 9.0: Hand back process Produce a report (min 250 words) to detail the hand back...
Assessment 9.0: Hand back process Produce a report (min 250 words) to detail the hand back process as defined by the Infrastructure Controller, and detail the factors that should be considered as part of the hand back process including the potential areas for special consideration which should be confirmed. Detail the requirements for maintenance records which form part of the hand back process. Write it in text if you know the answer as I don't understand the handwriting
Assessment 5.0: Hand back process Produce a report (min 300 words) to detail the hand back...
Assessment 5.0: Hand back process Produce a report (min 300 words) to detail the hand back process as defined by the infrastructure controller and detail the factors that should be considered as part of the hand back process including the potential areas for special consideration which should be confirmed. Detail the requirements for construction records which form part of the hand back process. The assets will be handed-back to the procuring authority at contract expiration. It is good practice to...
PYTHON    Generates a list of datetimes given a list of dates and a list of...
PYTHON    Generates a list of datetimes given a list of dates and a list of times. All possible combinations of date and time are contained within the result. The result is sorted in chronological order. For example, Input: >>> timetable([date(2019,9,27), date(2019,9,30)], [time(14,10), time(10,30)]) Output: [datetime(2019,9,27,10,30), datetime(2019,9,27,14,10), datetime(2019,9,30,10,30), datetime(2019,9,30,14,10)] Current code: from datetime import date, time, datetime def timetable(dates, times): lis = []    for c in times: for y in dates: x = f"(datetime{y},{c})" lis.append(x) #doesn't work at all
PYTHON GAME OF PIG The game of Pig is a simple two player dice game in...
PYTHON GAME OF PIG The game of Pig is a simple two player dice game in which the first player to reach 100 or more points wins. Players take turns. On each turn a player rolls a six-sided die. After each roll: a) If the player rolls a 1 then the player gets no new points and it becomes the other player’s turn. b) If the player rolls 2-6 then they can either roll again or hold. If the player...
Write a python script to calculate the average length of the game, Shortest game, longest game...
Write a python script to calculate the average length of the game, Shortest game, longest game and overall length of the game we need a python script that calculates the average length of a snake and ladder game. ie the number of moves it takes a single player to win the game. Then you run the game several times and will compare the results to come up with the required data(length of the game and number of moves )
PYTHON: Implement the sieve of Eratosthenes: a function for computing prime numbers, known to the ancient...
PYTHON: Implement the sieve of Eratosthenes: a function for computing prime numbers, known to the ancient Greeks. Choose an integer n. This function will compute all prime numbers up to n. First insert all numbers from 1 to n into a set. Then erase all multiples of 2 (except 2); that is, 4, 6, 8, 10, 12, . . . . Erase all multiples of 3, that is, 6, 9, 12, 15, ... . Go up to √ n. The...
In this python program , you are to build a trivia game. The game should present...
In this python program , you are to build a trivia game. The game should present each question – either in order or randomly – to the player, and display up to four possible answers. The player is to input what they believe to be the correct answer.   The game will tell the player if they got it right or wrong and will display their score. If they got it right, their score will go up. If they got it...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT