-1

I am trying to make an simple python Rock, Paper, Scissors, game. Here is my entire code.

import random

# The AI Respond, will be random.

print('Welcome to Rock, Paper, Scissors Game! \n')

UserInput = input("Please enter Rock, Paper, or Scissors, to start the game. \n")

BotChoicelist = ["Rock", "Paper", "Scissors", "Rock", "Paper", "Scissors", "Rock", "Paper", "Scissors"]
BotAwnser = random.sample(BotChoicelist, 1)

UserScore = 0

#If1
if "Rock" or "rock" in UserInput:
    if "Rock" in BotAwnser:
        print("Bot choose Rock, Tie")
    if "Paper" in BotAwnser:
        print("Bot choose Paper, Bot won.")
        print("Your score is:")
        print(UserScore - 1)
    if "Scissors" in BotAwnser:
        print("Bot choose Scissors, You won.")
        print("Your score is:")
        print(UserScore + 1)
   
#if2
if "Paper" or "paper" in UserInput:
    if "Paper" in BotAwnser:
        print("Bot choose Paper, Tie")
    if "Scissors" in BotAwnser:
        print("Bot choose Scissors, Bot won.")
        print("Your score is:")
        print(UserScore - 1)
    if "Rock" in BotAwnser:
        print("Bot choose Rock, You won.")
        print("Your score is:")
        print(UserScore + 1)

The problem is no matter what i enter at UserInput it will start the If1 and If2, how can i fix that? To be more clear here is the output:

Welcome to Rock, Paper, Scissors Game! 

Please enter Rock, Paper, or Scissors, to start the game. 
AnyThingHere
Bot choose Scissors, You won.
Your score is:
1
Bot choose Scissors, Bot won. 
Your score is:
-1
Hunk_
  • 1
  • 1
  • you must check what then input is and write an exit or return statement so that program wont continue from that point. – Albin Paul Aug 02 '20 at 11:11

2 Answers2

0
if UserInput in ["rock","Rock"]:
   #do something 
#if2
elif str(UserInput).lower() in ["paper"]:
  #do soemthing else
elif (another expression)

Please search the web for control-flow and logic statements

Abhishek Dujari
  • 2,343
  • 33
  • 43
0
if "Rock" or "rock" in UserInput:

does not do what you think it does.

It does not check if either "Rock" or "rock" are substrings of UserInput. Instead, it checks if "Rock" is true, or if "rock" is a substring of UserInput.

"Rock" is a 'truthy' value, meaning that in practice your if condition becomes:

if True or "rock" in UserInput:

which can be simplified to

if True:

So your if statement doesn't really do anything at all.

Changing the condition to something like if "Rock" in UserInput or "rock" in UserInput: will help, but you may want to look into lower(), in order to simplify the condition.

L.Grozinger
  • 2,280
  • 1
  • 11
  • 22