0
import random

def rockPaperScissors():
    choices = ['Rock', 'Paper', 'Scissors']
    win = {choices[1]: choices[0], choices[2]: choices[1], choices[0]: choices[-1]}
    lose = {choices[1]: choices[2], choices[0]: choices[1], choices[-1]: choices[0]}
    print('Welcome to ' + str(choices))

    for descision in range(1, 6):
        print('Choose your move! ' + str(choices))
        move = input()

        if move not in choices:
            print('You need to follow my instructions Sammy...\n')
        else:
            break
        
    if move in choices:
        print(".")
    else:
        print("Now you've done it")
        rockPaperScissors()

    randomChoice = random.choice(choices)
    check = {move: randomChoice}
    print(randomChoice)

    print('You chose ' + move + ' and I chose ' + randomChoice)
#
# VVV What I am having trouble with VVV #
#
    if check.items() == any(win.items()):
        print('You Win')

    elif check.items() == any(lose.items()):
        print('You Lose')

    else:
        print('Tie!')

rockPaperScissors()

This is my first python project. I decided to try and create a simple rock paper scissors program but am struggling to finalize the win/lose conditions. I have created a dictionary for a "win" and a "lose" which has all the conditions for each. What I am trying to do is create a new dictionary with "check" and then using the following if statement to see if it matches with a tuple in "win" or "lose". What comes back is always win, regardless of the actual outcome. I might be making this more complicated than needed but any thoughts would be appreciated.

if check in win: print('You Win')

I've tried this as an alternative but I receive a TypeError: unhashable type: dict

Hobo
  • 1
  • 1
  • 1
    Welcome to Stack Overflow. In your own words: what do you think is the purpose of a dictionary, generally? Why would someone prefer to use a dictionary over, for example, a list? Given that purpose, do you see how that applies to solving the problem? For example: given the user's `move`, can you see how to use the `win` dictionary in order to *find out directly* which `randomChoice` value means that the user should win? If you know what that value is, can you think of a simple way to write logic, using that value and the `randomChoice` variable, to decide whether the user won? – Karl Knechtel May 05 '23 at 02:36
  • 2
    "What I am trying to do is create a new dictionary with "check" and then using the following if statement to see if it matches with a tuple in "win" or "lose"" - this does not make sense, firstly because neither `win` nor `lose` contains tuples, and second because it is dramatically over-complicating the problem. – Karl Knechtel May 05 '23 at 02:38
  • I don't think you need to use the "lose" dictionary, because lose and win are relative, either lose or win. You also don't need the 'check' dictionary, you can use this judgment directly:` if win[move] == randomChoice: print("You Win")` – 911 May 05 '23 at 02:59

0 Answers0