0

I apologise if this question's too simple; this is a program in Python 3 about rock paper scissors. The problem is when the user puts in the input (for simplicity's sake, I've been testing with just '1'/ rock for the user and '3'/scissors for the enemy), the first if-statement doesn't activate and instead prints 'you lost'. I don't get what I'm doing wrong here,because even when I go and print user choice in line 6 it prints out 1. The if statement is just not working. Why?

print("Welcome to the Rock, Paper, Scissors game online!")
user_choice = input("Type 1 for Rock, 2 for Paper, 3 for Scissors.")
enemy_choice = 3

def rps(user_choice, enemy_choice):
  print(user_choice)
  if user_choice == 1:
    print("You won!")
  elif user_choice == enemy_choice:
    print("You drew.")
  else:
    print("You lost.")
 
print(rps(user_choice, enemy_choice))
  • 1
    Because you are comparing user input `user_choice` which has default type `str` with variables of `int` type. You might need to convert user input to `int` type with `int()` function. Simply add `user_choice = int(user_choice)` before `enemy_choice = 3` – Bijay Regmi Apr 09 '22 at 09:41
  • Thank you for the feedback! I think that works now! – Yijie Shen Apr 09 '22 at 14:11

0 Answers0