Rock paper scissors, skipping a result

python, random

Solution

you should not use `random.randrange(3)` three times. This may e.g. give you the following numbers: 1, 2 and then 0. So the code which is then executed would be:

if (1 == 0):
   ...
elif (2 == 1):
   ...
elif (0 == 2):
   ...

and none of the conditional blocks of the if statements would be executed.

Instead do something like this:

computerChoice = random.randrange(3)
...
if computerCoice == 0:
  ...
elif computerChoice == 1:
  ...
elif computerChoice == 2:
  ...
else
  raise Exception("something is definitively wrong here")

Problem

``` import random for i in range(3): user = str(input("Please enter your choice: ")) if (random.randrange(3)) == 0 : print("Computer chooses Rock") if user == "scissors" : print("computer wins") elif user == "paper" : print("player wins") else : print("tie") elif (random.randrange(3)) == 1 : print("Computer chooses Paper") if user == "rock" : print("computer wins") elif user == "scissors" : print("player wins") else : print("tie") elif (random.randrange(3)) == 2 : print("Computer chooses Scissors") if user == "paper" : print("computer wins") elif user == "rock" : print("player wins") else : print("tie") ``` The formatting is a bit weird on here (havent used this website before). I dont know the reason but i dont know why this code sometimes skips a result. if anyone could help that would be great. This is what is produced when it is run a couple of times ``` enter your choice: scissors Computer chooses Rock computer wins enter your choice: scissors Computer chooses Scissors tie enter your choice: scissors Computer chooses Rock computer wins ================================ RESTART ================================ Please enter your choice: scissors Please enter your choice: rock Computer chooses Rock tie Please enter your choice: rock Computer chooses Rock tie ``` I dont understand why it skips a result. Seems to happen randomly

Original source