Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PLEASE help! I have to make a rock paper sissors game in Python 3.4 or later. th

ID: 3579170 • Letter: P

Question

PLEASE help! I have to make a rock paper sissors game in Python 3.4 or later. this has to be using three different files, User.py , Users.py, and rps.py

Here are the instructions of what it has to contain and the outcome of how the menu should look like. Thanks!!!

User Class

Write a class named user and save it as a file named User.py. The user class should have the following data attributes:

__username To store the name of the player

__wins To store the number of wins

__ties To store the number of ties

__losses To store the number of losses

__created To store when the user account was created

__init__ This method takes 4 parameters, the username, wins, ties, and losses (when initializing the last 3 will be zeroes eg. (John,0,0,0)) It should create __username, __wins, __ties, and __losses based on those parameters and it should create __created based on the current time.

get_username Returns the value of __username field

get_user_wins Return the value of the __wins field

set_user_wins Takes in 1 parameter and sets __wins to that parameter

get_user_ties Returns the value of the __ties field

set_user_ties Takes in 1 parameters and sets __ties to that parameter

get_user_losses Returns the value of the __losses field

set_user_losses Takes in 1 parameter and sets __losses to that parameter

get_round Returns the current round number (not the next) HINT: return (wins + ties + losses)

get_age This method calculates the difference between the current time and the value of the __age field. It should return a string based on the age of the user. For example, this method should return the following: 30s if the user was created 30 seconds ago 15m if the user was created 15 minutes ago 1h if the created was posted 1 hour, 10 minutes, and 42 seconds ago

display_user Displays the username and stats (check sample output for formatting)

Note that the string returned from __get_age is only concerned with the largest unit of time. If the user is 0 to 59 seconds old, the value returned from __get_age will end with an “s” for “seconds”. If the user is some number of minutes old, it will end with an “m” and ignore the seconds. Likewise, if the user is 1 or more hours old, it will ignore both the minutes and seconds. To work with time, you’ll need to use Python’s time module. The documentation for that module is available here: https://docs.python.org/3.4/library/time.html

HINT: If we have a user that wins a round and want to increment their wins stat. user.get_user_wins() will get the current number of wins (it is an integer) we add one with + 1 we pass that number as a parameter to user.set_user_wins(new incremented wins) in working code: user.set_user_wins(user.get_user_wins()+1)

Users Class

Write a class named users and save it as a file named Users.py. The users class should have the following data attributes:

__user_list Is a list that will store each user

__rps_file_name To store the name of the file in which we read and write to. “rps.dat” so simply self.__rps_file_name = “rps.dat”

def load_users will attempt to use pickle to read the list of users into user_list from the file “rps.dat”

def save_users will attempt to use pickle to write the list of users, user_list, to the file “rps.dat”

##CRUD OPERATIONS##

def create_user Takes in a parameter, username, and checks to see if it exists. If it exists we return False, if it doesn’t exist, we add it to the list setting the wins, ties, losses to 0 and return True. If the name exists, we print the error: [!]Error: This User already exists.

def read_user Takes in a parameter, username, and checks to see if it exists. If it exists, we return the True AND the user object which has the same name. If it doesn’t exist, we return False and the user object. At the beginning of the function set found_user = None. We will return True, found_user or return False, found_user. To check if a user exists, we will compare each user name in the list (for user in self.__user_list:) to username. So compare each user.get_name() to username If the name doesn’t exist, we print the error: [!]Error: This User doesn't exist.

def update_user Takes in a parameter, a user, We find the user in the list and update users wins, losses, and ties using the accessor methods. We will get the current loaded users stats and update the user that is saved in the list to these new stats Eg. user.set_user_wins(current_user.get_user_wins) If the name doesn’t exist, we print the error: [!]Error: This User doesn't exist.

def display_highscore Takes in no parameters. Uses the list of users and creates a ranking of the Win percentage based on the wins divided by the rounds. It ranks everyone on the list from 1-N, N being the length of the list. Don’t worry about ranking ties in the highscore. Eg. if 2 people have a .50 Win percentage either can be first

HINT: This is one way to do this Start with making separate duplicate list temp_list = list(self.__user_list) With this temp_list we can use temp_list.remove(user) to remove a user. Think about the when we did max and first_pass… cur_max_user = user. cur_max_ratio = (user.get_user_wins/user.get_round()) If the next users ratio is greater than the max..make it the new user and the ratio..then at the end delete it..do this until the temp_list length is 0

RPS.py

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 outside 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.

HINT: To help clean up code and prevent duplicate code making these functions will help.

1. It would be easy to have 3 functions to display each menu.

2. It would also be easy to have a function that takes in the range of numbers for a menu, makes sure they are valid, and returns a choice.

Examples:

#main menu

choice = get_choice(1,4)

#game menu choice = get_choice(1,3)

#round menu choice = get_choice(1,3)

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

Rock Paper Scissors

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

[1] Start a New Game

[2] Load a Game

[3] Display High scores

[4] Exit

RESTART: /Usersjtwyp6/Desktop/TT1040 -RPS Manag []Error: Could not find previous users game data. Rock Paper Scissors [1] Start a New Game Load a Game [3] Display High Scores 41 Exit What would you like to do? If rps.dat does exist Rock Paper Scissors [1] Start a New Game Load a Game [3] Display High Scores 41 Exit What would you like to do? What is your name Johnny Hello Johnny. Let's play! RPS Game Menu [1] Play a Round [2] View Stats [31 Exi What would you like to do? 2 Username: Johnny Wins Ties Losses Age 4s RPS Game Menu Play a Round 21 View Stats 31 Ex What would you like to do? 1 Round 1 Rock 2] Paper 31 Scissors What would you like to do? 3 Rock beats Scissors. You lose RPS Game Menu [1] Play a Round 21 View Stats 31 Exit What would you like to do? 3 Rock Paper Scissors [1] Start a New Game [2] Load a Game [3] Display High Scores 41 Ex What would you like to do? 3 Win% Wins Ties Losses Rank Name Stephanie 0.50 1 0 1 ohn 0.33 ohnny 0.00 Rank N Win% W Losses Stephanie 0.50 0 0.33 2 0.00 0 Rock Paper Scissors Lij Start a New Game [2] Load a Game Display High Scores Rock, Paper, Scissors Game Final Project 41 Exit What would you like to do? 2 What is your name? [!]Error: This User doesn't exist. Rock Paper Soiss [lj Start a New Game [2] Load a Game [3] Display High Scores 4 Exit What would you like to do? What is your name []Error: This User already exists. Rock Paper Scissors [1] Start a New Game (2) Load a G [3] Display High Scores

Explanation / Answer

#!/usr/bin/env python
# -*-coding:utf-8-*-
import time
from time import sleep
import random

sus="-"*35
depo=["rock","paper","scissors"]
while True:
x=input("rock , paper, scissors: ")
if x not in depo:
print ("Dont cheat!")
continue

pc=random.choice(depo)
sleep(0.5)
print (("Computer picked {}.").format(pc))
if x==pc:
sleep(0.5)
print ((" It's a draw. {}").format(sus))
elif x=="rock" and pc=="scissors":
sleep(0.5)
print ((" You win.rock beats scissors {}").format(sus))
elif x=="paper" and pc=="rock":
sleep(0.5)
print ((" You win.paper beats rock {}").format(sus))
elif x=="scissors" and pc=="paper":
sleep(0.5)
print ((" You win.scissors beats paper {}").format(sus))
else:
sleep(0.5)
print ((" You lose. {} beats {} {}").format(pc,x,sus))
input()

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote