part of my code is unreachable in vscode, Iam trying to build basic rock paper scissors game

161 Views Asked by At

I am working on rock paper scissors game in order to learn python but my code is being greyed out/unnreachable, how would you solve it?

import random

def play():
    user = input("What is your choice'r' for rock, 'p' for paper, 's' for scissors\n")
    computer = random.choice(['r','p','s'])

    if user==computer:
        return 'tie'        

        def is_win(player, opponent):
            return 'You won'
    
    return 'You lost'

#FROM HERE IT IS UNREACHABLE

def is_win(player, opponent):
  
    if (player == 'r' and opponent == 's') or (player == 's' and opponent == 'p') \
        or (player == 'p' and opponent == 'r'):
        return True 

        print(play())
1

There are 1 best solutions below

0
Kavindu Ravishka On

I tried to regenerate your code

There were three wrong places at the same place

def is_win(player, opponent):
    return 'You won'
  1. Here it should be if , not def
  2. You have added extra indent to this block
  3. The arguments should be user,computer , not player,opponent

And the last one. I don't know whether it's a typing mistake happened while posting the question here.

  1. print(play()) should be outside of the is_win function