Python Forum
HELP---problems with rock paper scissors games
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
HELP---problems with rock paper scissors games
#1
Im having problems with the while loop terminating the rock paper scissors game once it gets to the choice variable to say no. Also when i initially enter my input in the beginning, it will only give me 'tie' back in the shell. It wont give any other response. Its like the random choice isnt working. BTW im running in python shell 3.5.4.


-----
import random

ROCK=1
PAPER=2
SCISSORS=3
keeprunning = True

while keeprunning == True:
user = input("rock/paper/scissors: ")
roll = random.randint(1,3)
if user == 'rock' or user == 'Rock' and 'roll' == 'ROCK':
print('tie')


elif user == 'rock' or user == 'Rock' and 'roll' == 'PAPER':
print('you lose')

elif user == 'rock' or user == 'Rock' and 'roll' == 'SCISSORS':
print('you win')


elif user == 'paper' or user == 'Paper' and 'roll' == 'ROCK':
print('you win')


elif user == 'paper' or user == 'Paper' and 'roll' == 'PAPER':
print('tie')


elif user == 'paper' or user == 'Paper' and 'roll' == 'SCISSORS':
print('you lose')


elif user == 'scissors' or user == 'Scissors' and 'roll' == 'SCISSORS':
print('tie')


elif user == 'scissors' or user == 'Scissors' and 'roll' == 'ROCK':
print('you lose')


elif user == 'scissors' or user == 'Scissors' and 'roll' == 'PAPER':
print('you win')


choice = input('Do you want to play another game?: ')
if choice == 'yes' or 'Yes':
keeprunning == True
else:
keeprunning == False
print('Good game')

import random

ROCK=1
PAPER=2
SCISSORS=3
keeprunning = True

while keeprunning == True:
    user = input("rock/paper/scissors: ")
    roll = random.randint(1,3)
    if user == 'rock' or user == 'Rock' and 'roll' == 'ROCK':
        print('tie')
        
        
    elif user == 'rock' or user == 'Rock' and 'roll' == 'PAPER':
        print('you lose')
      
    elif user == 'rock' or user == 'Rock' and 'roll' == 'SCISSORS':
        print('you win')
       
        
    elif user == 'paper' or user == 'Paper' and 'roll' == 'ROCK':
        print('you win')
        
        
    elif user == 'paper' or user == 'Paper' and 'roll' == 'PAPER':
        print('tie')
        
        
    elif user == 'paper' or user == 'Paper' and 'roll' == 'SCISSORS':
        print('you lose')
        
        
    elif user == 'scissors' or user == 'Scissors' and 'roll' == 'SCISSORS':
        print('tie')
        
        
    elif user == 'scissors' or user == 'Scissors' and 'roll' == 'ROCK':
        print('you lose')

        
    elif user == 'scissors' or user == 'Scissors' and 'roll' == 'PAPER':
        print('you win')

     
    choice = input('Do you want to play another game?: ')
    if choice == 'yes' or 'Yes':
       keeprunning == True
    else:
        keeprunning == False
        print('Good game')
Reply
#2
Ok, there's a lot to say about this, so I'll break it into parts. But first, next time you post code, please put it in code tags so the indentation is preserved.
(Sep-15-2017, 04:25 PM)kalt91 Wrote: Its like the random choice isnt working.
# ...snip...

roll = random.randint(1,3)

random.choice() works fine, but you never call it. Instead, you're getting a number (either 1, 2, or 3).
Quote:
if user == 'rock' or user == 'Rock' and 'roll' == 'ROCK':
#                                       ^^^^^^

You never compare the value of the variable roll anyway, so it doesn't matter what random.randint() returns. Instead, you compare the string "roll" with a couple of different things, which would always be False.
 
Quote:
elif user == 'rock' or user == 'Rock' and 'roll' == 'PAPER':
#                  ^^^^

AND has a higher precedence than OR, so that line is exactly the same as this one:
elif (user == 'rock') or (user == 'Rock' and "roll" == "PAPER"):
...so if you type "rock", you'll tie every single time, regardless of what the opponent does. But only "rock" all lowercase. If you type "Rock" or "ROCK" or "rOcK", then you might not tie anymore.
Reply
#3
Take a look at https://python-forum.io/Thread-Multiple-...or-keyword
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  how to compare two cards games? python_beginner99 7 3,692 Nov-30-2021, 06:53 PM
Last Post: deanhystad
  I attempted to make a rock paper scissors bot for homework Intellectual11 3 2,889 Jun-24-2021, 08:00 PM
Last Post: deanhystad
Question Rock, paper, scissors spelling error banidjamali 6 3,170 Jan-19-2021, 02:51 PM
Last Post: banidjamali
  Rock, Paper, Scissors Game kramon19 2 5,319 Jan-10-2020, 08:18 AM
Last Post: perfringo
  I need help with a python Rock Paper Scissors game urgently. Riff_Raff 3 5,821 Dec-05-2018, 09:13 PM
Last Post: nilamo
  Rock, Paper, Scissors Advanced that saves, loads, and keeps statistics EvanCahill 0 5,198 Jul-21-2018, 07:32 PM
Last Post: EvanCahill
  Rock Paper Scissors Warmlawpk441 4 5,013 Oct-11-2017, 10:55 AM
Last Post: gruntfutuk
  Rock paper scissors game samiraheen 3 6,340 Oct-03-2017, 07:07 PM
Last Post: buran
  The Python Book altered rock paper scissors Python_Noob 0 2,908 Sep-18-2017, 06:13 AM
Last Post: Python_Noob
  Rock, Paper, Scissors game help.. hentera 3 5,033 May-19-2017, 10:56 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

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