-1

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())
Rabbid76
  • 202,892
  • 27
  • 131
  • 174
  • 1
    Please use code blocks around all your code snippets :) – Yohann Boniface Jun 15 '22 at 18:38
  • 3
    You know python is a language, where the correct indention is very important. By the way you have formatted your question, it's rather hard to say, whether it is malformated just in the question or also in the code ... Please reformat your question so that your code looks **exactly** like in your IDE. If you don't know how to do that, have a look at https://stackoverflow.com/editing-help – derpirscher Jun 15 '22 at 18:45
  • 4
    And whats the `def is_win(...)` doing there in the middle of that function. While that is, in principle, perfectly legal, I don't suppose you meant to do that, but you would rather want to do something like `if is_win(player, opponent):` instead (and again, move it to the correct indention level!) – derpirscher Jun 15 '22 at 18:49

1 Answers1

-1

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
Kavindu Ravishka
  • 711
  • 4
  • 11