In: Computer Science
I'm working on a python programming problem where I have to write a program that plays rock paper scissors.
our 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 computer should select the weapon most likely to beat the user, based on the user’s 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 user’s 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 user’s 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:
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:
hi ,
please find program and out attached below.
kindly upvote.
import random
rockCount = 0
paperCount = 0
sciCount = 0
compWinCt = 0
userWinCt = 0
drawCt = 0
comp_choice = "p"
def startOfProgram():
play_game = input("wanna play again\n"
"y/n").lower()
if play_game == "y" or play_game == "yes" or play_game ==
"Y":
main()
elif play_game == "n" or play_game == "no" or play_game ==
"N":
print("Computer won", compWinCt, "times.")
print("User won", userWinCt, "times.")
print("Draw games count is: ",drawCt)
print("User picked Rock", rockCount, "times.")
print("User picked Paper", paperCount, "times.")
print("User picked Scissors", sciCount, "times.")
quit()
else:
print("not a valid choice, try again")
startOfProgram()
def RandomChoice():
comp_choice = random.randint(1, 3)
if comp_choice == 1:
comp_choice = "r"
elif comp_choice == 2:
comp_choice = "p"
elif comp_choice == 3:
comp_choice = "s"
return comp_choice
def ComputerChoice():
if rockCount == 0 and paperCount == 0 and sciCount == 0:
return RandomChoice()
else:
if (rockCount > paperCount) and (rockCount > sciCount):
comp_choice == "r"
elif (paperCount > rockCount) and (paperCount >
sciCount):
comp_choice == "p"
elif (sciCount > paperCount) and (sciCount >
rockCount):
comp_choice == "s"
return comp_choice
def main():
# set count for a zero
global rockCount
global paperCount
global sciCount
global compWinCt
global userWinCt
global drawCt
comp_choice = ComputerChoice()
user_choice = input("Please enter from menu below \n"
"r/R for rock,\n"
"p/P for paper \n"
"s/S for scissors \n"
"q/Q to quit ")
if comp_choice == "r" :
if user_choice == "r" or user_choice == "R":
print("match draw")
rockCount += 1
drawCt += 1
elif user_choice == "p" or user_choice == "P":
print("user won. user:paper vs computer:Rock")
userPaperCt += 1
userWinCt += 1
elif user_choice == "s" or user_choice == "S":
print("user loose. user:Scissors vs Computer:Rock")
sciCount += 1
compWinCt += 1
else:
print("Try again")
startOfProgram()
if comp_choice == "p":
if user_choice == "r" or user_choice == "R":
print("user loose. user:Rock vs Computer:Paper")
rockCount += 1
compWinCt += 1
elif user_choice == "p" or user_choice == "P":
print("draw match")
paperCount += 1
drawCt += 1
elif user_choice == "s" or user_choice == "S":
print("user won. user:Scissors vs computer:Paper")
sciCount += 1
userWinCt += 1
startOfProgram()
if comp_choice == "s":
if user_choice == "r" or user_choice == "R":
print("user won. user:Rock vs Computer:Scissors")
rockCount += 1
userWinCt += 1
elif user_choice == "p" or user_choice == "P":
print("user loose. user:Paper vs Computer:Scissors")
paperCount += 1
compWinCt += 1
elif user_choice == "s" or user_choice == "S":
print("draw match")
sciCount += 1
drawCt += 1
startOfProgram()
main()

thanks