Need help on stopping the score from resetting every game,
this is my code so far and its not working.
This is part of a function that checks who's the winner etc.
def winner ():
global Win
if alist [0] == player1 and alist[1] == player1 and alist[2] ==player1:#top line horizontal
Win = 'player1'
return True
elif alist[3] == player1 and alist[4] == player1 and alist[5] ==player1:#middleline horizontal
Win = 'player1'
return True
this statement determines the score and whether to start another game.
if winner():
if Win == 'player1':
print("player1 is winner")
p1score = p1score+1
elif Win == 'player2':
print("player2 is winner")
p2score = p2score+1
print('Player1s score =', p1score,'Player2s score =', p2score)
print("Would you like to play again(yes or no)")
restart = input("")
if restart == 'yes':
return gamemode()
Ok so at the end of the game the score displays correctly, but when another game is played it resets?
def playervscomputer():
global Player1Score
Player1Score = 0
global ComputerScore
ComputerScore = 0
players = [name, 'computer']
global turn
turn = random.randint(0,1)
while True:
print('its\s %s\'s turn' % players[turn])
if winner1():
#Check if people have won
if Win == 'player1':
print("player1 is winner")
Player1Score = Player1Score+1
print("player1s score is", Player1Score, 'Computer Score=', ComputerScore)
print("would you like to play again?(yes or no)")
restart = input("")
if restart =='yes':
return main()
else:
print("Thanks for playing")
elif Win == 'Computer':
print("Computer is winner")
ComputerScore = ComputerScore+1
print('Player1s score =', Player1Score,'Computers score =', ComputerScore)
Any ideas or any help on it keeping the scores after a few games have been played.
Thanks