-1

I am just learning Python and this is a working Rock Paper Scissors game that I've coded. I was looking at it and it was a bit tedious to type all of the different type faces, and I just overall feel like I'm over-complicating it. Is there a was to make this more simple?

import random
print("Rock, Paper, Scissors, Shoot!")
options = ['Rock', 'Paper', 'Scissors']
bot_choice = random.choice(options) 
user_choice = (input("(What would you like to play?...)"))
while user_choice == 'Rock' or 'rock' or 'Paper' or 'paper' or 'Scissors' or 'scissors':
if bot_choice == user_choice:
    print("Game:", bot_choice,"!", "Tie! Try Again!")
    break
elif bot_choice == 'Paper' and user_choice == 'Rock' or 'rock' or 'ROCK':
    print("Game:", bot_choice,'!', "You lose!")
    break
elif bot_choice == 'Rock' and user_choice == 'Scissors' or 'scissors' or 'SCISSORS':
    print("Game:", bot_choice,"!", "You lose!")   
elif bot_choice == 'Scissors' and user_choice == 'Paper' or 'paper' or 'PAPER':
    print("Game:", bot_choice,"!", "You lose!")
elif user_choice != ('Rock') and user_choice != ('Paper') and user_choice != ('Scissors'):
    print("Bad input! Try again!")
    break
else:
    print("Game:", bot_choice,"!", "You win!")
    break
Malvur
  • 1
  • 2
    Your code doesn't work, due to https://stackoverflow.com/q/15112125/3001761. Once you have **working code** that you think could be improved, that's more appropriate for [codereview.se]. – jonrsharpe Nov 02 '21 at 17:10

1 Answers1

2

You can simplify this in a few ways. First you should make the user input lowercase before comparing.

user_choice = input("(What would you like to play?...)").lower()

So if the user inputs "RoCk", the variable will have contain the value "rock". As @jonrsharpe mentioned, the code as it stands now won't work because of the way you used or. But that's not really relevant to your question.

We can also simplify the winning logic in a more compact manner. First, identify each input with a number (let's use the index in the choices list), and then we will do logic on these numbers. If the user chose the option with index 1 higher than the bot (where 1 higher than 2 will be 0), they win. A clean way to write this condition is (user_choice - bot_choice) % 2 == 1.

In all we get

import random
print("Rock, Paper, Scissors, Shoot!")
options = ['rock', 'paper', 'scissors']
bot_choice = random.randint(2) # The bot chooses 0, 1, or 2


user_choice = None

# Repeatedly try to get user input
while user_choice not in options:
    user_choice = (input("(What would you like to play?...)")).lower()

user_choice = options.index(user_choice)  # will be 0, 1, or 2


if bot_choice == user_choice:
    print("Game:", options[bot_choice], "!", "Tie! Try Again!")
elif (user_choice - bot_choice) % 3 == 1:
    print("Game:", options[bot_choice], "!", "You win!")
else:
    print("Game:", options[bot_choice], "!", "You lose!")
Marcel
  • 958
  • 1
  • 7
  • 18
  • 1
    The code is much more compact. But it looks like there might be a small logic issue here. If the user chooses '"paper" (index = 1) and bot chooses "rock" (index = 0), user loses. Shouldn't the user win in this case? – unityJarvis Nov 02 '21 at 17:56
  • 1
    Yes, you’re right, it should be the other way round. Edited the post. – Marcel Nov 03 '21 at 01:03