Python Forum
Rock, Paper, Scissors game help..
Thread Rating:
  • 2 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rock, Paper, Scissors game help..
#1
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)]
Reply
#2
What do you get?
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#3
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.
Reply
#4
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.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  I attempted to make a rock paper scissors bot for homework Intellectual11 3 2,866 Jun-24-2021, 08:00 PM
Last Post: deanhystad
Question Rock, paper, scissors spelling error banidjamali 6 3,138 Jan-19-2021, 02:51 PM
Last Post: banidjamali
  Rock, Paper, Scissors Game kramon19 2 5,290 Jan-10-2020, 08:18 AM
Last Post: perfringo
  I need help with a python Rock Paper Scissors game urgently. Riff_Raff 3 5,752 Dec-05-2018, 09:13 PM
Last Post: nilamo
  Rock, Paper, Scissors Advanced that saves, loads, and keeps statistics EvanCahill 0 5,163 Jul-21-2018, 07:32 PM
Last Post: EvanCahill
  Rock Paper Scissors Warmlawpk441 4 4,970 Oct-11-2017, 10:55 AM
Last Post: gruntfutuk
  Rock paper scissors game samiraheen 3 6,305 Oct-03-2017, 07:07 PM
Last Post: buran
  The Python Book altered rock paper scissors Python_Noob 0 2,875 Sep-18-2017, 06:13 AM
Last Post: Python_Noob
  HELP---problems with rock paper scissors games kalt91 2 4,069 Sep-15-2017, 04:51 PM
Last Post: micseydel
  Rock Paper Scissors game codeobri 3 13,343 Apr-28-2017, 01:02 AM
Last Post: codeobri

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020