So, I'm making this game in python. The thing is, in scissors, paper and rock there can be different combinations like .. Rock and paper, Rock and scissors, and so on. So how would I make this without doing heaps of elif statements.
import random
random_choice = ["Scissors", "Paper", "Rock"][random.randint(0, 2)]
player_input = raw_input("What's your choice (Scissors, Paper, or Rock)")
if player_input not in ["Scissors", "Paper", "Rock"]:
print("Not valid choice")
raw_input()
exit()
if player_input == random_choice:
print("You both choose %s" % random_choice)
elif player_input == "Rock" and random_choice == "Scissors":
print("You picked Rock and the bot picked Scissors, you win!")
raw_input()
#And so on making heaps of elif's for all the combinations there can be.
So how do we make this game without having to do so many elif statements or type less code. Surely there has to be a better programming sequence for dealing with these types of things?
if "Scissors" or "Paper" or "Rock" not in player_inputwon't do what you expect it to. - Timplayer_input not in ['Scissors', ...]. I'd also wrap it in a loop so when the user keeps giving you garbage input you keep asking for what you want (right now, if theifwas correct) you only ask twice. - Nick T