Menu

[Solved]-Trying Fix Code Project Get Wins Losses Ties Statistics Accurate Def Stats Player Import R Q37246022

I am trying to fix my code for my project. How do I get thewins, losses, and ties statistics to be accurate? It is under defstats(player)

import random
def beginninggame():
while True:
print(“Welcome to Rock, Paper, Scissors!”)
print(“1. Start New Gamen2. Load Gamen3. Quit”)
while True:
enterchoice = int(input(“Enter Choice: “))
if((enterchoice == 1)|(enterchoice==2)):
startgame(enterchoice)
break
elif(enterchoice==3):
quit()
break
else:
print(“Enter only 1, 2, or 3, please!”)
continue

def startgame(mode):
  
name = input(“What’s your name? “)
if(mode==1):
player=[name, 0, 0, 0]
print(“Hello”, name, “, Let’s play!”)
elif(mode==2):
player = []
try:
scorefile = open(name+”.rps”, “r”)
linenumber = 0
for line in scorefile:
if(linenumber!=0):
player.append(int(line))
else:
player.append(line[:-1])
linenumber+=1
scorefile.close()
print(“nWelcome back, “, name, “, Let’s play!”)
except:
print(“n”, name, “, your game could not be found.n”)
beginninggame()
game(player)

def game(player):
print(“Round “, (player[1]+player[2]+player[3]+1))
print(“1. Rockn2. Papern3. Scissors”)
while True:
move = int(input(“What would you like to do? “))
if(0<=move<=3):
break
else:
print(“nPlease enter 1, 2, or 3 please!”)
continue
computer = random.randint(1,3)
if(move==computer):
result = “You Tie!”
elif((move==1)&(computer==3)):
result = “You Win!”
elif((move==1)&(computer==2)):
result = “You Lose.”
elif((move==2)&(computer==1)):
result = “You Win!”
elif((move==2)&(computer==3)):
result = “You Lose.”
elif((move==3)&(computer==2)):
result = “You Win!”
elif((move==3)&(computer==1)):
result = “You Lose.”
options=[“”, “Rock”, “Paper”, “Scissors”]
print(“You chose “, options[move], “. The computer chose “,options[computer], “. “, result)
player[move]+=1   
question(player)

def question(player):
print(“What would you like to do?”)
print(“1. Play Againn2. View Statisticsn3. Quit”)
while True:
choice2 = int(input(“What will it be? “))
if(choice2==1):
game(player)
break
elif(choice2==2):
stats(player)
break
elif(choice2==3):
savegame(player)
break
else:
print(“nEnter either 1, 2, or 3 please!”)
continue

def savegame(player):
try:
scorefile = open(player[0]+”.rps”, “w”)
for line in player:
scorefile.write(“%sn” % line)
scorefile.close()
print(“n”, player[0], “, your game was saved.”)
except:
print(“Sorry “, player[0], “, your game couldn’t be saved”)
quit()

def stats(player):
print(player[0], “, here are your game play statistics…”)
print(“Wins: “, player[1], “nLosses: “, player[2], “nTies: “,player[3])
if(player[3]!=0):
print(“Win/Loss Ratio: “, round(player[1]/player[2], 2))
else:
print(“Win/Loss Ratio: 1”)
question(player)

beginninggame()

Expert Answer


Answer to I am trying to fix my code for my project. How do I get the wins, losses, and ties statistics to be accurate? It is unde… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *