Python Forum

Full Version: Rock, Paper, Scissors game help..
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm having a very minor issue that I can't seem to figure out. When the user enters "quit" I want the program to display their wins/losses. What am I doing wrong?



from random import randint
import sys

#create a list of play options
print("Let's play a game of Rock, Paper, Sissors!")
t = ["Rock", "Paper", "Scissors", "Quit"]
 
#assign a random play to the computer
computer = t[randint(0,2)]
wins = 0
losses = 0

#set player to False
player = False
 
while player == False:
#set player to True
    player = input("Rock, Paper, Scissors, or Quit? ")
    if player == computer:
        print("Tie!")
    elif player == "Rock":
        if computer == "Paper":
            print("You lose!", computer, "covers", player)
        else:
            print("You win!", player, "smashes", computer)
    elif player == "Paper":
        if computer == "Scissors":
            print("You lose!", computer, "cut", player)
        else:
            print("You win!", player, "covers", computer)
    elif player == "Scissors":
        if computer == "Rock":
            print("You lose...", computer, "smashes", player)
        else:
            print("You win!", player, "cut", computer)
    elif player == "Quit":
            wins = wins + 1
            losses = 0
            print("Wins: ", wins, "Losses: ", losses) 
            print("Thanks for playing!")
            sys.exit()
    else:
        print("That's not a valid play. Check your spelling!")
        sys.exit()
    #player was set to True, but we want it to be False so the loop continues
    player = False
    computer = t[randint(0,2)]
What do you get?
In the future, you'll get answers very fast if you share the actual output you're getting.

That said, I'm going to guess you always see "Wins: 0 Losses: 0". You have a variable to hold how many wins/losses there are, but it doesn't look like you ever actually use them.
Every time you print "you win" or "you lose", you should be updating the appropriate variable (wins or losses). Then, when they quit, print them without modifying them. Also, I would use break instead of sys.exit() to get out of the loop. Using sys.exit() is a bit heavy handed.