This question is more of a "I SWEAR MY CODE SHOULD WORK"...
If you look at the section of my "Rock, Paper, Scissors" games I wrote while trying to learn the basics of python, there is a section that converts the user's input str to a number.
playerChoice = input('Rock, paper, scissors: ')
if playerChoice is ('Rock'or'rock'):
playerChoiceNum = 0
print ('PLAYER CHOICE IS ROCK')
if playerChoice is 'Paper' or 'paper':
playerChoiceNum = 1
print ('PLAYER CHOICE IS PAPER')
if playerChoice is 'Scissors' or 'scissors' or 'Scissor' or 'scissor':
playerChoiceNum = 2
print ('PLAYER CHOICE IS SCISSORS')
For some reason, python sets playerChoiceNum to '0' each time no matter what you type in as an input. I tried using == comparison operator's instead of 'is' to no avail.
Sometimes it decides to get stuck on playerChoiceNum = 2 and sometimes it is stuck on playerChoiceNum = 0.
I'm curious as to why this is happening as I feel it will teach me more about how python actually functions as language, but for the life of me cannot figure out what is going on. Any help would be appreciated!
Here is my full "game" code if you want to try running it for yourself.
from random import randint
playerScore = 0
while playerScore < 3:
print('hey person, please choose rock, paper or scissors to try and beat the computer 3 times')
playerChoice = input('Rock, paper, scissors: ')
if playerChoice is ('Rock'or'rock'):
playerChoiceNum = 0
print ('PLAYER CHOICE IS ROCK')
if playerChoice is 'Paper' or 'paper':
playerChoiceNum = 1
print ('PLAYER CHOICE IS PAPER')
if playerChoice is 'Scissors' or 'scissors' or 'Scissor' or 'scissor':
playerChoiceNum = 2
print ('PLAYER CHOICE IS SCISSORS')
computerChoiceNum = randint(0,2)
if computerChoiceNum == 0:
print('COMPUTER HAS CHOSEN ROCK')
elif computerChoiceNum == 1:
print('COMPUTER HAS CHOSEN PAPER')
elif computerChoiceNum == 2:
print('COMPUTER HAS CHOSEN SCISSORS')
if playerChoiceNum == computerChoiceNum:
print('DRAW')
if playerChoiceNum == 0 and computerChoiceNum == 1:
print('COMPUTER WINS')
if playerChoiceNum == 0 and computerChoiceNum == 2:
print('PLAYER WINS')
playerScore+=1
if playerChoiceNum == 1 and computerChoiceNum == 2:
print('COMPUTER WINS')
if playerChoiceNum == 1 and computerChoiceNum == 0:
print('PLAYER WINS')
playerScore+=1
if playerChoiceNum == 2 and computerChoiceNum == 0:
print('COMPUTER WINS')
if playerChoiceNum == 2 and computerChoiceNum == 1:
print('PLAYER WINS')
playerScore+=1
print('DEBUG INFO:\n'
'Player Choice: ' + str(playerChoice)+'\n' +
'Player Choice Number Conversion: ' + str(playerChoiceNum)+'\n' +
'Computer Choice: ' + str(computerChoiceNum)+'\n' +
'Player Score: ' + str(playerScore)+'\n')