Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am working on a rock paper scissor game on python that game where the user competes with the cpu. The program will allow a

I am working on a rock paper scissor game on python that game where the user competes with the cpu.

The program will allow a human user to play Rock, Paper, Scissors with the computer. Each round of the game will have the following structure:

The program will choose a weapon (Rock, Paper, Scissors), but its choice will not be displayed until later so the user doesnt see it.

The program will announce the beginning of the round and ask the user for his/her weapon choice

The two weapons will be compared to determine the winner (or a tie) and the results will be displayed by the program

The next round will begin, and the game will continue until the user chooses to quit

The computer will keep score and print the score when the game ends

The computer should select the weapon most likely to beat the user, based on the users previous choice of weapons. For instance, if the user has selected Paper 3 times but Rock and Scissors only 1 time each, the computer should choose Scissors as the weapon most likely to beat Paper, which is the users most frequent choice so far. To accomplish this, your program must keep track of how often the user chooses each weapon. Note that you do not need to remember the order in which the weapons were used. Instead, you simply need to keep a count of how many times the user has selected each weapon (Rock, Paper or Scissors). Your program should then use this playing history (the count of how often each weapon has been selected by the user) to determine if the user currently has a preferred weapon; if so, the computer should select the weapon most likely to beat the users preferred weapon. During rounds when the user does not have a single preferred weapon, the computer may select any weapon. For instance, if the user has selected Rock and Paper 3 times each and Scissors only 1 time, or if the user has selected each of the weapons an equal number of times, then there is no single weapon that has been used most frequently by the user; in this case the computer may select any of the weapons.

At the beginning of the game, the user should be prompted for his/her input. The valid choices for input are:

R or r (Rock)

P or p (Paper)

S or s (Scissors)

Q or q (Quit)

At the beginning of each round your program should ask the user for an input. If the user inputs something other than r, R, p, P, s, S, q or Q, the program should detect the invalid entry and ask the user to make another choice.

Your program should remember the game history (whether the user wins, the computer wins, or the round is tied).

At the end of the game (when the user chooses q or Q), your program should display the following:

The number of rounds the computer has won

The number of rounds the user has won

The number of rounds that ended in a tie

The number of times the user selected each weapon (Rock, Paper, Scissors)

### Code so Far please fix to follow the guidlines mentioned above

import random

def main():

print('ROCK PAPER SCISSORS in Python')

print()

print('Rules: 1) Rock wins over Scissors.')

print(' 2) Scissors wins over Paper.')

print(' 3) Paper wins over Rock.')

def rock_paper_scissors():

guess = 'r','p','s'

computer_score = 0

person_score = 0

rounds = 1

total_rounds= 1

p=0

r=0

s=0

while (computer_score < total_rounds and person_score < total_rounds):

print("******************* ROUND #", rounds, "*******************")

rock_paper_scissors = input("Pick your throw: [r]ock, [p]aper, or [s]cissors? ")

if p==0 and r==0 and s==0 and p==s and r==s:

computer = random.choice(guess)

elif p>r and p>s:

computer = s

elif r>p and r>s:

computer = p

elif s>p and s>r:

computer = r

elif s==p and s>r:

computer=random.choice(s,p)

elif s==r and s>p:

computer=random.choice(s,r)

elif r==p and r>s:

computer=random.choice(r,p)

if rock_paper_scissors == computer:

print('Tie!')

rounds +=1

if rock_paper_scissors==p:

p +=1

elif rock_paper_scissors==r:

r =r+1

elif rock_paper_scissors==s:

s +=1

elif (rock_paper_scissors == 'p' and computer == 'r'):

print('Computer threw rock, you win!')

person_score=person_score+1

p +=1

rounds +=1

elif (rock_paper_scissors == 'r' and computer == 's'):

print('Computer threw scissors, you win!')

person_score=person_score+1

r +=1

rounds +=1

elif(rock_paper_scissors == 's' and computer == 'p'):

print('Computer threw paper, you win!')

person_score=person_score+1

s +=1

rounds +=1

elif(rock_paper_scissors == 'r' and computer == 'p'):

print('Computer threw paper, you lose!')

computer_score=computer_score+1

r +=1

rounds +=1

elif (rock_paper_scissors == 's' and computer == 'r'):

print('Computer threw rock, you lose!')

computer_score=computer_score+1

s +=1

rounds +=1

elif(rock_paper_scissors == 'p' and computer == 's'):

print('Computer threw scissors, you lose!')

computer_score=computer_score+1

p +=1

rounds +=1

print ("Your score:", person_score)

print ("Computer's score:", computer_score)

print("keep playing more rounds Enter 1 or for quit Enter q")

x= int(input())

if x==1:

if computer_score> person_score:

total_rounds = computer_score + 1

else:

total_rounds = person_score + 1

return

main()

rock_paper_scissors()

Please help me improve my code that I mentioned above also please test the code to see that it follow all the guidlines that I mentioned above. Also please properly indent the code when you post it so i dont get to confused.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Solaris 11.2 System Administration (oracle Press)

Authors: Harry Foxwell

1st Edition

007184421X, 9780071844215

More Books

Students also viewed these Databases questions