not printing if both statements are the same

76 Views Asked by At

I'm trying to print draw if players and computer choose the same variable, It can not printing if both statements are the same at the moment it just ends after the computers choice and ignores the if statement

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

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

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

#Write your code below this line 

players_choice = input("What do you choose? Type 0 for Rock, 1 for Paper or 2 for Scissors. ")

if players_choice == "0":
  print(rock)
elif players_choice == "1":
   print(paper)
elif players_choice == "2":
  print(scissors)

import random

print("Computer chooses:")

computer_options = [rock, paper, scissors]

computer_choice = random.choice(computer_options)

print(computer_choice)

if computer_choice == players_choice:
  print("Draw")
1

There are 1 best solutions below

1
Faisal Nazik On

Currently, you are comparing the players_choice which can be "0", "1" or "2" with computers choice that can be rock, paper or scissors,

That's why it can never be equal and can print Draw.

So simply you can set players_choice to something like below in your if, else blocks

if players_choice == "0":
    players_choice = rock
    print(rock)
elif players_choice == "1":
    players_choice = paper
    print(paper)
elif players_choice == "2":
    players_choice = scissors
    print(scissors)

So then this comparison will make more sense;

if computer_choice == players_choice:
  print("Draw")

Complete Updated Snippet:

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

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

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

players_choice = input("What do you choose? Type 0 for Rock, 1 for Paper or 2 for Scissors. ")

if players_choice == "0":
    players_choice = rock
    print(rock)
elif players_choice == "1":
    players_choice = paper
    print(paper)
elif players_choice == "2":
    players_choice = scissors
    print(scissors)

import random

print("Computer chooses:")

computer_options = [rock, paper, scissors]

computer_choice = random.choice(computer_options)

print(computer_choice)

if computer_choice == players_choice:
  print("Draw")