Hello I am beginner programmer in python and I am having trouble with this code. It is a rock paper scissors game I am not finished yet but it is supposed to print "I win" if the user does not pick rock when the program picks scissors. But when the program picks paper and the user picks rock it does not print "I win". I would like some help thanks. EDIT - answer was to add indent on else before "i win" thank you everybody.
import random
ask0 = input("Rock, Paper, or Scissors? ")
list0 = ["Rock", "Paper", "Scissors"]
r0 = (random.choice(list0))
print("I pick " r0)
if ask0 == r0:
print("Tie")
elif ask0 == ("Rock"):
if r0 == ("Scissors"):
print("You Win")
else:
print("I win")
CodePudding user response:
import random
ask0 = input("Rock, Paper, or Scissors? ")
list0 = ["Rock", "Paper", "Scissors"]
r0 = (random.choice(list0))
print("I pick " r0)
if ask0 == r0:
print("Tie")
elif ask0 == ("Rock"):
if r0 == ("Scissors"):
print("You Win")
else:
print("I win")
Need to add else in Scissors condition.
CodePudding user response:
Once Python as entered the elif
statement, it will automatically skip the outer else
. So, if you want it to print "I win" inside the elif
statement, you need to indent your else
statement like so:
import random
ask0 = input("Rock, Paper, or Scissors? ")
list0 = ["Rock", "Paper", "Scissors"]
r0 = (random.choice(list0))
print("I pick " r0)
if ask0 == r0:
print("Tie")
elif ask0 == ("Rock"):
if r0 == ("Scissors"):
print("You Win")
else:
print("I win")