1
I know you can do it in other ways, but I’ve done it limited to ifs. I wonder why I’m reversing the results in the last part of the code.
from random import randint
pedra, papel, tesoura = "1", "2", "3"
print("[1] Pedra\n[2] Papel\n[3] Tesoura")
p = int(input("Pense no que vai jogar: \n"))
d, e, c = "Você perdeu!", "Empate!", "Você ganhou!"
pe, pa, te = "Pedra", "Papel", "Tesoura"
if p == 1:
print("Você jogou:", pa)
elif p == 2:
print("Você jogou:", pe)
elif p == 3:
print("Você jogou:", te)
pc = randint(1, 3)
if pc == 1:
print("PC jogou:", pa)
elif pc == 2:
print("PC jogou:", pe)
elif pc == 3:
print("PC jogou:", te)
if pc == p:
print(e)
elif pc == 1 and p == 2:
print(d)
elif pc == 2 and p == 1:
print(c)
elif pc == 3 and p == 1:
print(d)
elif pc == 1 and p == 3:
print(c)
elif pc == 3 and p == 2:
print(c)
elif pc == 2 and p == 3:
print(d)
We speak Stone, Paper and Scissors... You put 1 = paper, 2 = stone, 3 = Scissors. Then you left your code confused. Change the values to 1 = stone, 2 = paper, 3 = scissors and redo the
if
. It will make it easier for you. The error is in the other ifs and not in the last two.– Paulo Marques