I've been coding a simple dice roll game to practice Python. I've got the basic mechanics worked out, but I want to have it so that the player receives 5 points every time the game is won. I've tried just simply adding 5 to the variable (PLAYER_TOTAL in the case), but when the code goes back to play another game it reverts back to 0.
Here's my code so far:
import random
def gameIntro():
print('''This is a dice roll game. Dice are rolled, and you recieve money
if you are equal to the total. Are you ready?''')
print('Yes or no?')
return input().lower().startswith('y')
def gamePlay():
PLAYER_TOTAL = 0
dieRoll = random.randint(1, 6)
dieRoll1 = random.randint(1, 6)
print()
print('Guess a number from 1 to 12')
playerGuess = int(input())
diceTotal = dieRoll + dieRoll1
if playerGuess == diceTotal:
print('Woo! You got it! Plus $5 for you!')
PLAYER_TOTAL += 5
print()
print('You have ' + str(PLAYER_TOTAL))
else:
print('Sorry you didn\'t match the dice roll. Try again?')
input().lower().startswith('y')
while False:
print('Goodbye!')
break
gameIntro()
while True:
gamePlay()
I've been mainly using the pdf "Invent Your Own Computer Games With Python", which hasn't been much help on this topic. Any suggestions on how I can fix this?