Welcome to 16892 Developer Community-Open, Learning,Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm traying to make a simple rock paper scissors game but it seems that the if and elif statement do not respond. It only prints the else statement.

Here's the code:

from random import randint

rock = '''
    _______
---'   ____)
      (_____)
      (_____)
      (____)
---.__(___)
'''

paper = '''
    _______
---'   ____)____
          ______)
          _______)
         _______)
---.__________)
'''

scissors = '''
    _______
---'   ____)____
          ______)
       __________)
      (____)
---.__(___)
'''
t = [rock, paper, scissors]

player = int(input("choose 0 for rock and 1 for paper and 2 for scissors 
"))
cpu = t[randint(0,2)]

print(t[player])
print(cpu)  

if player == 0 and cpu == 2:
  print("YOU WIN")

elif cpu == 0 and player == 2:
  print("YOU LOSt")

elif player == 1 and cpu == 0:
  print("you win")

elif cpu == 1 and player == 0:
  print(" YOU LOST")

else:
  print("this is invalid input! ")  

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
3.9k views
Welcome To Ask or Share your Answers For Others

1 Answer

I think you want cpu = randint(0,2) so that it's just the int. Then later when you need the string, replace cpu with t[cpu]


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to 16892 Developer Community-Open, Learning and Share
...