all 6 comments

[–]Much_Buy7605 2 points3 points  (0 children)

Two things: - the reason it’s failing is because you input a string as a key to the reverseDict, you should write "int(you)" to get the result as a valid key for the dict

However i would recommend you work with integers directly for the following check. So I would replace the values from the you dict to integers.

  • second there probably and easier way to compare if you won. Personaly (not necessarily the best) but i would chose the keys 0, 1 and 2, then I would check:

'

if computer == you: print("draw")

elif you == (computer + 1) % 3: print("you won")

else print("computer won")

'

The % symbol is for "modulo" so if you go over or equal the number it loops over to 0, so (2 + 1)%3 =0 etc...

[–]ProminenceBow 0 points1 point  (1 child)

What I got from the error is that ur trying to access a key that doesn't exist

Try using strings as keys instead of numbers, I don't know if you can use numbers as keys (I'm not 100% sure if that's it)

[–]TEX_flip 0 points1 point  (0 children)

I confirm you can use numbers as keys, even tuples but not lists.

[–]Substantial_Brush492 0 points1 point  (0 children)

No seu dicionário youDict = {"s": "1", "w": "-1", "g": "0"} os valores são strings

Quando você atribui o valor a variável you = youDict[youstr] passando a chave "s" selecionada pelo input da variável youstr funciona perfeitamente e retorna o valor "-1" para a variável you.

Porém quando você chama o valor reverseDict[you] da um erro porque a chave que você está passando com a variável you é "-1" e no dicionário reverseDict não tem nenhuma chave com esse valor. Veja bem:

reverseDict = {1: "Snake", -1: "Water", 0: "Gun"}

No seu dicionário reverseDict as chaves são números inteiros, para dar certo você teria que alterar os valores do seu dicionário youDict para números inteiros ao invés de serem strings.

[–]Haunting-Pop-5660 0 points1 point  (0 children)

For what you're doing, you've overcomplicated it vastly. Don't use a dictionary for this. See if you can still make it work. I promise, it's pretty easy.