I am trying to assign value to the variables winsP1 and winsP2 by playing a random number game in my function 'determineWinner'. The values of winsP1 and winsP2 will be the number of times that each player wins the random number game.
The trouble I am running into is I am not able to pull the values from my function and use them outside of the function in my next block of code that tells me which player ultimately won the most rounds.
import random
answer = input("Play the game?")
winsP1 = 0
winsP2 = 0
def determineWinner(winsP1, winsP2):
from random import randint
player1 = randint(1,10)
player2 = randint(1,10)
#time.sleep(1)
print("Player 1:", player1)
#time.sleep(1)
print("Player 2:", player2)
#time.sleep(1)
if player1==player2:
print("This round is a tie!")
winsP1 + 1
winsP2 + 1
elif player1>player2:
winsP1 + 1
print("Player 1 wins this round!")
elif player2>player1:
print("Player 2 wins this round!")
winsP2 + 1
#time.sleep(1)
for i in range(10):
determineWinner(winsP1, winsP2)
if answer == "y" or answer == "Y" or answer == "yes" or answer == "Yes":
if winsP1>winsP2:
print()
print("The score totals are:")
print("Player one: " + str(winsP1))
print("Player two: " + str(winsP2))
print()
print("Player 1 wins with a score of", str(winsP1) + "!")
print()
elif winsP2>winsP1:
print()
print("The score totals are:")
print("Player One: " + str(winsP1))
print("Player two: " + str(winsP2))
print()
print("Player 2 wins with a score of", str(winsP2) + "!")
print()
elif winsP1==winsP2:
print()
print("The score totals are:")
print("Player one: " + str(winsP1))
print("Player two: " + str(winsP2))
print()
print("It's a tie!")
print()