Reputation: 37
why do I keep getting "r" in results instead of "0" when I type r or R in input?
from random import randint
# Input
print("Rock: R Paper: P Scissors: S")
x = input("Please pick your choice: ")
y = randint(0,2)
if x.lower() == "r":
x == 0;
print("value entered ", x, "value generated ", y)
Upvotes: 0
Views: 62
Reputation: 39926
x == 0;
is a boolean evaluating to False
in your case. It tests if the value of x is equal to 0.
What you want is x = 0
;
Upvotes: 1
Reputation: 8910
There are two problems:
x = 0
(assignment), not x == 0
(comparison).if x.lower() == "r":
) is always going to be false, because your input has a trailing newline (that is, x
will usually be something like "r\n"
. You want if x.strip().lower() == "r":
instead.Upvotes: 0