1

I'm trying to create a very simple rock/paper/scissors game (I'm new to python) and I am trying to understand why the result of the code below always results to "It's a draw". When using the boolean 'and' operator in my code I would think that when both conditions are met it would print "You win". Why doesn't it, what am I missing? I have looked at documentation here and google using conditional statements and from what I have found I am using them correctly but apparently not...

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

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

scissors = '''
    _______
---'   ____)____
          ______)
       __________)
      (____)
---.__(___)
'''
import random

test_seed = int(input("Create a seed number: "))
random.seed(test_seed)


human_choice = input("What do you choose? Type 0 for rock, 1 for paper or 2 for scissors. ")
computer_choice = random.randint(0, 2)

if human_choice == 0:
  print(rock)
elif human_choice == 1:
  print(paper)
else:
  print(scissors)

print("Computer chose:")

if computer_choice == 0:
  print(rock)
elif computer_choice == 1:
  print(paper)
else:
  print(scissors)

if human_choice == 0 and computer_choice == 2:
  print("You win.")
elif human_choice == 1 and computer_choice == 0:
  print("You win.")
elif human_choice == 2 and computer_choice == 1:
  print("You win.")
elif computer_choice == 0 and human_choice == 2:
  print("You lose.")
elif computer_choice == 1 and human_choice == 0:
  print("You lose.")
elif computer_choice == 2 and human_choice == 1:
  print("You lose.")
else:
  print("It's a draw.")
Mamdlv
  • 540
  • 8
  • 23

1 Answers1

2

Very simple: You didn't cast the user input to integer value.. because you compare the values later to integers you need to cast it because by default user input is a string

Just chage this lineof code:

human_choice = input("What do you choose? Type 0 for rock, 1 for paper or 2 for scissors. ")

To this:

human_choice = int(input("What do you choose? Type 0 for rock, 1 for paper or 2 for scissors. "))
adir abargil
  • 5,495
  • 3
  • 19
  • 29