I have written the below code for a rock, paper, scissors game as my first bit of independent coding. I've tried every possible solution I can possibly think of to get a cumulative running total of wins, losses and draws, however every time it only shows me the most recent result - i.e. 1 win 0 losses 0 draws even on the 50th game if the most recent game was a win.
Can anybody suggest a way to solve this?
# Rock, Paper, Scissors!
import random
import time
print('Welcome to Rock, Paper, Scissors, a Python recreation of the classic game.')
print('The computer will randomly choose a sign at the start of the run for you to try to beat.')
print('Choose carefully...')
def fullgame():
compguess = random.randint(1, 3)
if compguess == 1:
compsign = 'rock'
elif compguess == 2:
compsign = 'paper'
else:
compsign = 'scissors'
playsign = input('Would you like to throw rock, paper or scissors? ')
while playsign != 'rock' and playsign != 'paper' and playsign != 'scissors':
print('You need to pick a valid sign!')
playsign = input('Would you like to throw rock, paper or scissors? ')
def numberallocator(rps):
if rps == 'rock':
return 1
elif rps == 'paper':
return 2
elif rps == 'scissors':
return 3
else:
print('That\'s not a valid sign!')
playguess = numberallocator(playsign)
numberallocator(playsign)
def game(cg, pg):
print('The computer is deciding...')
time.sleep(1)
print('The computer throws ' + compsign + ' and you throw ' + playsign + '...')
time.sleep(1)
if cg == pg:
print('It\'s a draw! You both picked ' + compsign)
return 'd'
else:
if cg == 1:
if pg == 2:
print('You win! Paper beats rock!')
return 'w'
elif pg == 3:
print('You lose! Rock beats scissors!')
return 'l'
elif cg == 2:
if pg == 1:
print('You lose! Paper beats rock!')
return 'l'
elif pg == 3:
print('You win! Scissors beats paper!')
return 'w'
else:
if pg == 1:
print('You win! Scissors beats rock!')
return 'w'
elif pg == 2:
print('You lose! Scissors beats paper!')
return 'l'
game(compguess, playguess)
playagain = 'y'
gamesplayed = 0
while playagain == 'y' or playagain == 'Y':
fullgame()
gamesplayed = gamesplayed + 1
print('You have played ' + str(gamesplayed) + ' games.')
playagain = input('Play again? y/n: ')
while playagain != 'y' and playagain != 'n':
print('You must pick y or n!')
playagain = input('Play again? y/n: ')
print('Thank you for playing rock, paper, scissors! This has been coded in Python by Ethan Lang!')
Thank you!