Question

Using python 3.7.3 Challenge: Rock, Paper, Scissors GamePDF Description: Create a menu-driven rock, paper, scissors game...

Using python 3.7.3 Challenge: Rock, Paper, Scissors GamePDF Description: Create a menu-driven rock, paper, scissors game in Python 3 that a user plays against the computer with the ability to save and load a game and its associated play statistics. Purpose: The purpose of this challenge is to assess the developer’s ability to create an interactive application with data persistence in Python 3. Requirements: Create a Rock, Paper, Scissors game in Python named rps.py according to the requirements specified in this document. Create a menu-driven rock, paper, scissors game that a user plays against the computer with the ability to save and load a game and its associated play statistics. The following Wikipedia article describes the game play. http://en.wikipedia.org/wiki/Rock-paper-scissors During a round of play the user chooses rock, paper, or scissors from a menu and the computer makes its choice randomly. For each round it is possible for the user to win, lose, or tie. The statistics that are to be maintained for a game are wins, losses, and ties. When a game is saved the user’s name and play statistics (wins, losses, and ties) are to be saved. When a game is loaded based on the user’s name the statistics are loaded and additional game play add to the loaded statistics. Optional alternative: You can create the game “Rock, Paper, Scissors, Lizard, Spock” instead of “Rock, Paper, Scissors”. Check out the following video on YouTube where the rules for “Rock, Paper, Scissors, Lizard, Spock” are covered. Rock Paper scissors Lizard Spock For menus in the game, the user makes a selection from the menu by entering the number of their choice. If the user enters something other than a number or a number in the range of the choices provided in the menu they are to be given feedback that their choice is not valid and asked for the input again. Under no circumstance should input from the user crash the program. When the program is run the following title, menu, and input prompt are to be displayed. Welcome to Rock, Paper, Scissors! Start New Game Load Game Quit Enter choice: If the user chooses 1 to start a new game they are to be prompted for their name and game play is to proceed after their name is entered. If the user chooses 2 to load a game then they should be taken to a prompt to enter a name that is to be used to load a saved game. If the user chooses 3 to quit the game the program is to exit. 1. Start New Game If the user chooses to start a new game the program is to prompt the user for their name using the following prompt. What is your name? After the name is entered the program is to respond with a line that is “Hello” followed by the name of the user, a period, and the phrase “Let’s play!” Example: Hello Dale. Let’s play! After the hello statement is presented to the user, game play is to proceed. Game play is described below in the Game Play section. 2. Load Game If the user chooses to load an existing game the program is to prompt the user for their name using the following prompt. What is your name? After the name is entered the program is to attempt to load a game file that is named based on the user name with an extension of .rps. For example, the file name for Justin is to be Justin.rps. If the file is found, the information about the game and statistics are to be loaded, a welcome back message is to be presented to the user, and game play is to proceed. The round number displayed is to be based on the number of rounds previously played. (Note: number of rounds previously played is sum of wins, losses, and ties.) Game play is described below in the Game Play section. The welcome back message is to be “Welcome back” followed by the user’s name, a period, and the phrase “Let’s Play!” Example: Welcome back Dale. Let’s play! If the file is not found, the user is to be presented with a message indicating the game could not be found and then presented with the startup menu described at the top of the requirements. The message is to be the user name followed by “, your game could not be found.” Example: Dale, your game could not be found. 3. Quit If the user chooses to quit, the program is to exit. Game Play This section describes game play. For each round a line that includes the round number is to be displayed followed by a menu that let’s the user choose Rock, Paper, or Scissors as their choice for the round as shown below. Round Rock Paper Scissors What will it be? The user makes their choice and the computer chooses randomly. The result of the round is to be displayed using the following format: You chose . The computer chose . You ! Example: You chose Paper. The computer chose Rock. You win! After the round the user is to be presented with the following prompt and menu. What would you like to do? Play Again View Statistics Quit Enter choice: If the user chooses 1 to play again, the user is to play another round. If the user chooses 2 to view statistics, the current statistics for the game are to be displayed. If the user chooses 3 to quit, the game and associated statistics are to be saved to a file and the program is to exit. 1. Play Again If the user chooses to play again the next round number is to be displayed and the user is to again choose Rock, Paper, or Scissors to play the round as described above. 2. View Statistics If the user chooses to view the statistics the following information is to be displayed: , here are your game play statistics… Wins: Losses: Ties: Win/Loss Ratio: Example: Dale, here are your game play statistics… Wins: 8 Losses: 7 Ties: 2 Win/Loss Ratio: 1.14 After the statistics are displayed, the user is to be presented with the menu shown above that is presented after playing a round. What would you like to do? Play Again View Statistics Quit Enter choice: 3. Quit If the user chooses to quit the game, the program is to automatically save the game and associated statistics in a game file that is named based on the user name with an extension of .rps. For example, the file name for Justin is to be Justin.rps. If there is an exception saving the file, an error message reporting the error is to be presented to the user. The message is to be “Sorry ” followed by the user’s name and “, the game could not be saved.” Additionally, the actual error provided by the Exception object is to be displayed on the next line. Example: Sorry Dale, the game could not be saved. If the file saves successfully the user is to be presented with a message indicating the success of the file save. The message is to be the user’s name followed by “, your game has been saved.” Example: Dale, your game has been saved. Finally, the program is to exit. File Format for .rps When a game is saved to an .rps file the information in the file is to include the following. User name Wins Losses Ties You can come up with your own file format. Just be sure what you write to the file you can read from the file and interpret and assign to variables in the program. You could, for example, have each piece of information on a separate line. When you write the data to the file you could put the name on the first line, the wins on the second line, the losses on the third line, and the ties on the fourth line. When you read the file you could read each line and know what the information on that line means because you’ve created the format. Example: Dale 8 7 2 Here, though, is a suggestion for a better way to save and load the file information. Section 9.3 in the textbook provides information on serializing objects. “Serializing an object is the process of converting the object to a stream of bytes that can be saved to a file for later retrieval.” You can create an object that holds the information that is to go into the file and then serialize it to save it into a file. You can then read the file and de-serialize it back into the object to use in the program. Study 9.3 Serializing Objects to learn how it works. Note that when you load a game, that is… load an .rps file, the statistics in the file need to be use to set variables in the program. During the game play the round number is displayed. Be sure that the round number displayed after loading a game is one more than the number of rounds that were played and saved in the file. The rounds played is the sum of the wins, losses, and ties. Sample Game Output Example 1 Welcome to Rock, Paper, Scissors! Start New Game Load Game Quit Enter choice: 1 What is your name? Dale Hello Dale. Let’s play! Round 1 Rock Paper Scissors What will it be? 2 You chose Paper. The computer chose Rock. You win! What would you like to do? Play Again View Statistics Quit Enter choice: 1 Round 2 Rock Paper Scissors What will it be? 1 You chose Rock. The computer chose Paper. You lose! What would you like to do? Play Again View Statistics Quit Enter choice: 2 Dale, here are your game play statistics… Wins: 1 Losses: 1 Ties: 0 Win/Loss Ratio: 1.00 What would you like to do? Play Again View Statistics Quit Enter choice: 3 Dale, your game has been saved. Example 2 Welcome to Rock, Paper, Scissors! Start New Game Load Game Quit Enter choice: 2 What is your name? Dale Welcome back Dale. Let’s play! Round 3 // Note: this is round 3 because two other rounds were in a saved file! Rock Paper Scissors What will it be? 3 You chose Scissors. The computer chose Paper. You win! What would you like to do? Play Again View Statistics Quit Enter choice: 3 Dale, your game has been saved. Testing Make sure you have thoroughly tested your program! Submission Put your rps.py file in a folder named RPS and zip the folder. The zip file is to be submitted for this assignment. If you create Rock, Paper, Scissors, Lizard, Spock, name your program rpsls.py and put it in a folder named RPSLS.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

code

solution

#random library import random def display(): print (please enter the option? \n) print(1. Play Again) print(2. View Statdef view (ni,d1): print (d1[name]+, play statistics...) print (Wins: +str (d1[wins])) print (Losses: +str(d1[losselse: return tie def play_Game (n, value): print (Round +str(n)) print(\ni. Rock) print(2. Paper) print(3. Scissors\print(1. Start a New Game) print (2. load_game Game) print(3. Quit) print() game_option = int (input (Enter option:

//output

Rock_Paper_Scissors 1. Start a New Game 2. load_game Game 3. Quit Enter option: 1 enter the name? sharm Hello sharm. Letsplease enter the option? 1. Play Again 2. View Statistics 3. Quit Enter option: 2 sharm, play statistics... Wins: 2 Losses: 0

//copyable code

#random library
import random
def display():
print("please enter the option? \n")
print("1. Play Again")
print("2. View Statistics")
print("3. Quit\n")
game_input = int(input("Enter option: "))
return game_input

def load_game():
n1 = input("Enter your name: ")
try:
f1 = open(n+".rps","r")
value = {"name": "", "wins": 0, "loss": 0, "tie": 0}
i1 = 0
for line in f1:
if i1 is 0:
value['name'] = line.strip()
elif i1 is 1:
value['wins'] = int(line)
elif i1 is 2:
value['loss'] = int(line)
elif i1 is 3:
value['tie'] = int(line)
i1 = i1 + 1
return value
except:
print("Hello "+n+" your game file does not found")
value = load_game()
return value

def quit(d1):
f1 = open(d1["name"]+".rps","w")
f1.write(d1['name']+"\n"+str(d1['wins'])+"\n"+str(d1['loss'])+"\n"+str(d1['tie']))
f1.close()
print(d1['name']+", your game has been saved.")

def view(n1,d1):
print(d1['name']+", play statistics...")
print("Wins: "+str(d1['wins']))
print("Losses: "+str(d1['loss']))
print("Ties: "+str(d1['tie']))
if d1['loss'] is 0:
print ("\nWin/Loss Ratio: 0")
else:
print("\nWin/Loss Ratio: "+str(round(d1['wins']/d1['loss'],2)))
game_input = display()
if game_input is 1:
play_Game(n1 + 1, d1)
elif game_input is 2:
view(n1,d1)
elif game_input is 3:
quit(d1)
else:
print("Enter a valid data")
view(n1,d1)

def check_game(x1):
if x1 is 1:
return "Rock"
elif x1 is 2:
return "Paper"
elif x1 is 3:
return "Scissors"
def win(u1,c1):
if u1 is 1 and c1 is 2:
return "c"
elif u1 is 1 and c1 is 3:
return "u"
elif u1 is 2 and c1 is 1:
return "u"
elif u1 is 2 and c1 is 3:
return "c"
elif u1 is 3 and c1 is 1:
return "c"
elif u1 is 3 and c1 is 2:
return "u"
else:
return "tie"
def play_Game(n,value):
print("Round "+str(n))
print("\n1. Rock")
print("2. Paper")
print("3. Scissors\n")
option = int(input("enter choice? "))
if option <= 3 and option >= 1:
comp = random.randint(1,3)
s = win(option,comp)
if s is "u":
print("You chose "+check_game(option)+". The computer chose "+check_game(comp)+". You win!")
value['wins'] = value['wins'] + 1
elif s is "c":
print("You chose " + check_game(option) + ". The computer chose " + check_game(comp) + ". You lose!")
value['loss'] = value['loss'] + 1
elif s is "tie":
print("You chose " + check_game(option) + ". The computer chose " + check_game(comp) + ". Game Tied")
value['tie'] = value['tie'] + 1
else:
print("Please enter a number that is in the range 1 to 3")
play_Game(n,value)
game_input = display()
if game_input is 1:
play_Game(n+1,value)
elif game_input is 2:
view(n,value)
elif game_input is 3:
quit(value)
else:
print("Enter a valid option!")

def newGame():
name = input("enter the name? ")
print("Hello "+name+". Let's Play!")
value = {"name":name,"wins":0,"loss":0,"tie":0}
play_Game(1,value)


print("1. Start a New Game")
print("2. load_game Game")
print("3. Quit")
print("")
game_option = int(input("Enter option: "))
if game_option is 1:
newGame()
elif game_option is 2:
value = load_game()
print("Welcome back, "+value['name']+ " let's play again!")
n = value['wins'] + value['loss'] + value['tie']
game_input = display()
if game_input is 1:
play_Game(n + 1, value)
elif game_input is 2:
view(n, value)
elif game_input is 3:
quit(value)
else:
print("Enter a valid choice!")

Add a comment
Know the answer?
Add Answer to:
Using python 3.7.3 Challenge: Rock, Paper, Scissors GamePDF Description: Create a menu-driven rock, paper, scissors game...
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
  • For this week’s assignment, we will be recreating the Rock, Paper, Scissors program using Object-...

    For this week’s assignment, we will be recreating the Rock, Paper, Scissors program using Object-Oriented Programming. You will be working with me on a team to build the program. I have already written my part of the program, and the Game.java file is attached. Your task will be to write a RockPaperScissors class that contains the following methods: getUserChoice: Has the user choose Rock, Paper, or Scissors. After validating the input, the method returns a String containing the user choice....

  • java pls Rock Paper Scissors Lizard Spock Rock Paper Scissors Lizard Spock is a variation of...

    java pls Rock Paper Scissors Lizard Spock Rock Paper Scissors Lizard Spock is a variation of the common game Rock Paper Scissors that is often used to pass time (or sometimes to make decisions.) The rules of the game are outlined below: • • Scissors cuts Paper Paper covers Rock Rock crushes Lizard Lizard poisons Spock Spock smashes Scissors Scissors decapitates Lizard Lizard eats Paper Paper disproves Spock Spock vaporizes Rock Rock crushes Scissors Write a program that simulates the...

  • CECS Project 1 RPS (Rock-Paper-Scissors) Game Use python This project asks you to practice . creating...

    CECS Project 1 RPS (Rock-Paper-Scissors) Game Use python This project asks you to practice . creating a new python file using pycharm . doing text- based input and output building your own algorithm using branching and loop Your program should operate as follows It must let the user choose from among three options of rock, paper, and scissors It shall play an honest game of RPS Display the choice the user made . If the user input is not one...

  • IN JAVA. Write a program that lets the user play the game of Rock, Paper, Scissors...

    IN JAVA. Write a program that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows. When the program begins, a random number in the range of 1 through 3 is generated. If the number is 1, then the computer has chosen rock. If the number is 2, then the computer has chosen paper. If the number is 3, then the computer has chosen scissors. Don’t display the computer’s choice yet....

  • (Java) Write a program that lets the user play the game of Rock, Paper, Scissors against...

    (Java) Write a program that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows. When the program begins, a random number in the range of 1 through 3 is generated. If the number is 1, then the computer has chosen rock. If the number is 2, then the computer has chosen paper. If the number is 3, then the computer has chosen scissors. Don’t display the computer’s choice yet. The...

  • Write a Python program (using python 3.7.2) that lets the user play the game of Rock,...

    Write a Python program (using python 3.7.2) that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows. 1. When the program begins, a random number in the range of 1 through 3 is generated. If the number is 1, then the computer has chosen rock. If the number is 2, then the computer has chosen paper. If the number is 3, then the computer has chosen scissors. (Don’t display the...

  • In python language Write a program that lets the user play the game of Rock, Paper,...

    In python language Write a program that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows: 1. When the program begins, a random number in the range of 1 and 3 is generated. 1 = Computer has chosen Rock 2 = Computer has chosen Paper 3 = Computer has chosen Scissors (Dont display the computer's choice yet) 2. The user enters his or her choice of “Rock”, “Paper", “Scissors" at...

  • Rock, Paper, Scissors (also known by several other names, see http://en.wikipedia.org/wiki/Rock p...

    Help needed in Perl language program! Note : Perl Language Rock, Paper, Scissors (also known by several other names, see http://en.wikipedia.org/wiki/Rock paper scissors) is an extremely popular hand game most often played by children. Often, it is used as a method of selection similar to flipping a coin or throwing dice to randomly select a person for some purpose. Of course, this game is not truly random since a skilled player can often recognize and exploit the non-random behavior of...

  • C++ Part 2: Rock Paper Scissors Game Write a program that lets the user play this...

    C++ Part 2: Rock Paper Scissors Game Write a program that lets the user play this game against the computer. The program should work as follows: When the program begins, a random number between 1 and 3 is generated. If the number is 1, the computer has chosen rock. If the number is 2, the computer has chosen paper. If the number is 3, the computer has chosen scissors. Don't display the computer's choice yet. Use a menu to display...

  • Java CSC252   Programming II    Static Methods, Enums, Constants, Random Rock Paper Scissors Write a program that...

    Java CSC252   Programming II    Static Methods, Enums, Constants, Random Rock Paper Scissors Write a program that allows the user to play "Rock, Paper, Scissors". Write the RPS class. All code should be in one file. main() will be part of the RPS class, fairly small, and contain only a loop that asks the user if they want to play "Rock, Paper, Scissors". If they say yes, it calls the static method play() of the RPS class. If not, the program...

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