Mr.Mango
Mr.Mango

Reputation: 21

(Noob) Writing Rock, Paper, Scissors in Python. The Tie option doesn't produce a tie result

This is my first time posting and using this site, sorry if this isn't the best way to ask. I have tried researching myself and looking for answers on this forum but each display i find is either a different language to my own or has a different issue. The issue I'm having is the game runs in terminal just as i would like except when it comes to a tie it doesn't register a tie and just begins a new game "choose your option or type quit to exit" on the next line. I am using Thonny as my editor and have followed the debugging procedure and it appears it just 'skips' the tie command. how can i fix this or is there some information or documentation you could point me towards to help me understand my issue. Thank-you

    #rock, paper, scissors
import random, sys
wins = 0
losses = 0
ties = 0
print('Let\'s play a game')
print('rock. paper. scissors')

while True:
    print('choose your option or type quit to exit')
    print('%s wins, %s losses, %s ties'%(wins, losses, ties))
    while True:
        playeroption = input()
        if playeroption == 'quit':
            sys.exit() # Quit the program.
        if playeroption == 'rock' or playeroption == 'paper' or playeroption == 'scissors':
            break # Break out of the player input loop.
        
    randomNumber = random.randint(0,2) #selecting computer options
    if randomNumber == 0:
        AIoption = 'Rock'
    elif randomNumber == 1:
        AIoption = 'Scissors'
    elif randomNumber == 2:
        AIoption = 'Paper'       
    if playeroption == AIoption: #player vs computer outcomes
        print('draw, i choose ' + str( AIoption) +'!')
        ties = ties + 1
        continue
    elif AIoption == 'Paper' and playeroption == 'rock':
        print('better luck next time i choose ' + (  AIoption))
        losses = losses + 1
        continue
    elif AIoption == 'Rock' and playeroption == 'scissors':
        print('better luck next time i choose ' + str(AIoption))
        losses = losses + 1
        continue
    elif AIoption == 'Scissors' and playeroption == 'paper':
        print('better luck next time i choose ' + str(AIoption))
        losses = losses + 1
        continue
    elif AIoption == 'Paper' and playeroption == 'scissors':
        print('you win human. I choose ' + (  AIoption))
        wins = wins + 1
        continue
    elif AIoption == 'Rock' and playeroption == 'paper':
        print('you win human. I choose ' + str(AIoption))
        wins = wins + 1
        continue
    elif AIoption == 'Scissors' and playeroption == 'rock':
        print('you win human. I choose ' + str(AIoption))
        wins = wins + 1
        continue

Upvotes: 2

Views: 81

Answers (1)

Max
Max

Reputation: 84

The problem here is, that your playeroption value is every time lowercase and you compare it with an uppercase value so your if playeroption == AIoption will never return a true. If you want to ignore case sensitivity you can do something like:

if playeroption.lower() == AIoption.lower()

So python will make both your string lowercase and then compare it and it will not matter if the first character is lowcase or uppercase.

You could also add the .lower() function to your if playeroption == 'rock' or playeroption == 'paper' or playeroption == 'scissors': like if playeroption.lower() == 'rock' ... then the user can enter the his option and it will not matter if the word begins low- or uppercase.

Upvotes: 1

Related Questions