Python Forum
Rock, Paper, Scissors game help.. - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: Rock, Paper, Scissors game help.. (/thread-3393.html)



Rock, Paper, Scissors game help.. - hentera - May-19-2017

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)]



RE: Rock, Paper, Scissors game help.. - sparkz_alot - May-19-2017

What do you get?


RE: Rock, Paper, Scissors game help.. - nilamo - May-19-2017

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.


RE: Rock, Paper, Scissors game help.. - ichabod801 - May-19-2017

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.