Question

hi can you please solve this python problem for me?? Three pets live in a happy...

hi can you please solve this python problem for me??

Three pets live in a happy house: dog, cat and a mouse. The dog often chases the cat,
the cat likes to chase the mouse, however the mighty dog runs away when it sees the
mouse. Develop a game which can be played by two
players. The program asks the two players (player1 and player2) to choose either 1
for dog, 2 for cat, or 3 for mouse. The rules for this game are simple:
The dog prevails over the cat
The cat prevails over the mouse
The mouse prevails over the dog
So if player1 chooses a dog and player2 chooses a cat, player1 wins. If player1
chooses a dog and player2 chooses a mouse, player2 wins, and so forth. If both
players choose the same pet, then the result will be draw. The players continue
playing until either player hits enter without choosing a number (1, 2 or 3). Each time
the game is run, the result is printed on the screen (for example, Player 1 wins or
Player 2 wins).
Hint:
 Define an indefinite loop which only breaks when either player enters an
empty string (hits enter with no entry).
 Within the loop, prompt Player 1 and Player 2 to enter 1 for dog, 2 for cat or 3
for mouse
 Based on the choices made by Player 1 and Player 2, your program prints out
the appropriate message, which can either be “draw”, “Player 1 wins” or
“Player 2 wins”.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
Thanks for the question.

Here is the completed code for this problem. 

Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. 

If you are satisfied with the solution, please rate the answer. 


Thanks
===========================================================================


# get user input from player
def getUserChoice(messsage):

    print('{} Please Select : [1] Dog [2] Cat [3] Mouse'.format(messsage))
    choice=input('Enter your choice: ')
    return  choice

# function determines the winner and returns the message
def winner(player1,player2):

    if player1=='1' and player2=='2':return 'Player 1 wins'
    elif player1=='2' and player2=='3':return 'Player 1 wins'
    elif player1=='3' and player2=='1':return 'Player 1 wins'
    elif player2=='1' and player1=='2':return 'Player 2 wins'
    elif player2=='2' and player1=='3':return 'Player 2 wins'
    elif player2=='3' and player1=='1':return 'Player 2 wins'
    elif player2==player1:return 'Draw'
    # when players entered anything other than 1 2 or 3
    else:return 'Invalid selection.'


def main():
    print('Welcome to Dog, Cat and Mouse Game')
    while True:
        playerOne = getUserChoice("Player 1")
        if playerOne=='':break # break out when player one didnt entered anything
        playerTwo = getUserChoice("Player 2")
        if playerTwo == '': break # break out when player two didnt entered anything
        winners = winner(playerOne,playerTwo)
        print(winners)
    print('Thanks for playing. Bye.')
main()

======================================================================================

Add a comment
Know the answer?
Add Answer to:
hi can you please solve this python problem for me?? Three pets live in a happy...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C only (not C++) Write a C program that simulates a game. There are two players...

    C only (not C++) Write a C program that simulates a game. There are two players (called Player1 and Player2). At the start of the game, each player chooses a number from 1 to 10 (cannot be the same). Then, the program will generate a random number from 1 to 10. The game ends when either Player1 or Player2 hits the number generated by the program. Display the winning message for the winner. Example output: Player 1: 6 Player 2:...

  • 5.12 A5 Program Do you want to play. a. game? The Big Bang Theory fans may...

    5.12 A5 Program Do you want to play. a. game? The Big Bang Theory fans may recognize Rock Paper Scissors Lizard Spock as a game of chance that expands on the standard Rock Paper Scissors game. It introduces two new hand signs and several more rules. The rules: • Scissors cuts Paper • Paper covers Rock • Rock crushes Lizard • Lizard poisons Spock • Spock smashes Scissors • Scissors decapitates Lizard • Lizard eats Paper • Paper disproves Spock...

  • C++ program This program involves writing a VERY simplified version of the card game War. You...

    C++ program This program involves writing a VERY simplified version of the card game War. You may know this game or not but my rules are these 1. Split the deck between player1 and player2. Only the face values matter (2-14) and not the suits 2. Each player puts a card down on the table. The higher face value wins that hand. If the card values match, you will simply indicate tie and neither player wins.The original rules would require...

  • Please help as it is very important task for me please write in Python code and...

    Please help as it is very important task for me please write in Python code and divide this into function and write comments for it 1. Ask the player’s name and welcome them to the game using their name. 2. Ask the player what is par for this game (number between 3-5 inclusive) 3. Ask the player what the distance to the hole for this game is (whole number between 195 and 250 inclusive) 4. Show the game menu: (I)nstructions...

  • Can somebody help me with this coding the program allow 2 players play tic Tac Toe....

    Can somebody help me with this coding the program allow 2 players play tic Tac Toe. however, mine does not take a turn. after player 1 input the tow and column the program eliminated. I want this program run until find a winner. also can somebody add function 1 player vs computer mode as well? Thanks! >>>>>>>>>>>>>Main program >>>>>>>>>>>>>>>>>>>>>>> #include "myheader.h" int main() { const int NUM_ROWS = 3; const int NUM_COLS = 3; // Variables bool again; bool won;...

  • Problem Statement: A company intends to offer various versions of roulette game and it wants you...

    Problem Statement: A company intends to offer various versions of roulette game and it wants you to develop a customized object-oriented software solution. This company plans to offer one version 100A now (similar to the simple version in project 2 so refer to it for basic requirements, but it allows multiple players and multiple games) and it is planning to add several more versions in the future. Each game has a minimum and maximum bet and it shall be able...

  • c language This assignment is to write a program to score the paper-rock-scissors game AGAIN. Each...

    c language This assignment is to write a program to score the paper-rock-scissors game AGAIN. Each of two players enters either P, R, or S. The program then announces the winner as well as the basis for determining the winner: “Paper covers rock”, “Rock breaks scissors”, “Scissors cut paper”, or “Draw, nobody wins”. The primary differences between this and previous two versions are described as below: (1) You MUST use a function to get the input value for the player’s...

  • Java Listed below is code to play a guessing game. In the game, two players attempt...

    Java Listed below is code to play a guessing game. In the game, two players attempt to guess a number. Your task is to extend the program with objects that represent either a human player or a computer player. boolean checkForWin (int guess, int answer) { System.out.println("You guessed" + guess +"."); if (answer == guess) { System.out.println( "You're right! You win!") ; return true; } else if (answer < guess) System.out.println ("Your guess is too high.") ; else System.out.println ("Your...

  • Please help me write a Pseudocode (please do NOT answer in JAVA or Python - I...

    Please help me write a Pseudocode (please do NOT answer in JAVA or Python - I will not be able to use those). Please ALSO create a flowchart using Flowgarithm program. Thank you so much, if answer is provided in Pseudocode and Flowchart, I will provide good feedback and thumbs up to the resonder. Thank you! Tic-Tac-Toe Game Write a program that allows two players to play a game of tic-tac-toe. Use a two- dimensional char array with three rows...

  • programming language c++ programming language c++ 1:25 #WW # 53% You may, if you wish, work...

    programming language c++ programming language c++ 1:25 #WW # 53% You may, if you wish, work in pairs; this means that a submission may have 2 names attached but those 2 people must have worked on the project. No free rides! The way to submit the program to me is as follows: put the entire program (main and any other functions) into a single compile. Compile it to be sure that you have the correct set of #include statements and...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT