Thank you lol. Now we shall never speak about this again haha.
The answer the user puts is invisible and it doesnt print the right text
print("Rock Paper Scissors ")
print("R, P, or S")
from getpass import getpass as input
one = input("Player 1 > ")
two = input("Player 2 > ")
if one == "R" or "r" and two == "P" or "p":
print("Player 2's paper smothers Player 1's rock!")
elif one == "R" or "r" and two == "S" or "s":
print("Player 1's rock smashes Player 2's scissors!")
elif one == "R" or "r" and two == "R" or "r":
print("Draw, no one wins!")
elif one == "S" or "s" and two == "S" or "s" :
print("Draw, no one wins!")
elif one == "P" or "p" and two == "P" or "p" :
print("Draw, no one wins!")
elif one == "P" or "p" and two == "R" or "r":
print("Player 1's paper smothers Player 2's rock!")
elif one == "P" or "p" and two == "S" or "s":
print("Player 2's scissors cut Player 1's paper to shreds!")
elif one == "S" or "s" and two == "R" or "r":
print("Player 2's rock smashes Player 1's scissors!")
elif one == "S" or "s" and two == "P" or "p":
print("Player 1's scissors shred Player 2's paper to shreds")
else:
print("Use R, P, or S next time" )
Thatās the point, so the other player canāt cheat.
So in Python, a non-empty string is always True. And Python is reading this like
if (one == "R") or ("r")
Since "r"
will return True, it doesnāt care what the users inputted. Instead, use the .upper()
method (makes the input uppercase, no matter what was actually inputted) like so:
one = input("Player 1 > ").upper()
two = input("Player 2 > ").upper()
if one == "R" and two == "P":
print("Player 2's paper smothers Player 1's rock!")
elif one == "R" and two == "S":
print("Player 1's rock smashes Player 2's scissors!")
elif one == two:
print("Draw, no one wins!")
elif one == "P" and two == "R":
print("Player 1's paper smothers Player 2's rock!")
elif one == "P" and two == "S":
print("Player 2's scissors cut Player 1's paper to shreds!")
elif one == "S" and two == "R":
print("Player 2's rock smashes Player 1's scissors!")
elif one == "S" and two == "P":
print("Player 1's scissors shred Player 2's paper to shreds")
else:
print("Use R, P, or S next time" )
I made the if statements a bit shorter, by the way.
Thanks for the help
Thereās a typo in 01- day 14 challenge.md:
WOW! Thatās alot in just 13 days.
It should have been āa lotā (2 words).
I put together the following code for the Rock, Paper, Scissors game for the 100 days of code. As you can see I was attempting to assign R, P and S an integer and then make them greater than each other depending on which option should win. It would only return that playerOne wins, and I dont know why. Not sure if this is even possible to do this way but could someone tell me if this thinking is in the right direction? Thank you!
playerOne = input("Player One select your move (R, P or S)")
playerTwo = input("Player Two select your move (R, P or S)")
R = int(1)
P = int(2)
S = int(3)
R>S and R<P and P>R and P<S and S>P and S<R
if playerOne > playerTwo:
print("Congrats Player One!")
elif playerTwo > playerOne:
print("Congrats Player Two!")
else:
print("Try again.")
You can wrap text in triple backticks (```) to format as code.
If you want to go a more arithmetic approach, then it might be something like this (Iāve tried doing it like that before):
R > S, S > P, P > S
by the rules. You canāt easily substitute in three easy integers because of the cycle.
So, letās say that the winner has a value 1 greater than the loser
R = 3
S = 2
P = 1
player = R
opponent = S
if player == opponent:
print('tie')
elif player - opponent == 1:
print('player wins')
else:
print('opponent wins')
R - S == 1
, S - P == 1
, but P - R
does not equal 1
, it equals -2
ā¦ However, -2
is similar to 1
, by mod 3. -2 % 3 == 1
. (Mod, or modulus, is the remainder of a division operator. -2 divided by 3 is -1, with remainder 1.)
Soā¦
if player == opponent:
print('tie')
elif (player - opponent) % 3 == 1:
print('player wins')
else:
print('opponent wins')
Pretty silly. But it works I guess.
Equivalent alternative:
dif = (player - opponent) % 3
if dif == 0:
print('tie')
elif dif == 1:
print('player wins')
elif dif == 2:
print('opponent wins')
else:
raise ValueError