I am trying to make a simple RPS game and can't see what I am doing wrong.
I declase pc_choise, player_choice and turn as global variables but I can't modify them in functions such as checkWinner()
.
If I print that value after the function has been called, it still has the initial value.
Code:
import random
import sys
pc_choices = ['r','p','s']
pc_choise = ''
player_choice = ''
turns = 0
print("\t\tWelcome to Rock Paper Scissors")
def getPcChoice():
return random.randint(1,3) - 1
def getUserChoice():
player_choice = input('Please choose: ')
turns = 1
if(player_choice.lower() not in pc_choices):
print('\nPlease use R, P, or S - *not case sensitive*\n')
getUserChoice()
else:
pc_choise = pc_choices[getPcChoice()]
print('\nYou picked ' + player_choice + ' and the PC picked ' +
pc_choise)
checkWinner()
def checkWinner():
if(player_choice.lower() == pc_choise.lower()):
print('Tie')
elif(player_choice.lower() == 'r' and pc_choise.lower() == 'p'
or player_choice.lower() == 'p' and pc_choise.lower() == 's'
or player_choice.lower() == 's' and pc_choise.lower() == 'r'):
print('You win! ')
else:
print('You lose! ')
getUserChoice()