#πŸ”’ Not sure what's wrong

101 messages Β· Page 1 of 1 (latest)

serene rover
#

Hello everyone. I am new to python and I was trying out a few projects.
This is a rock paper scissors game but I keep getting an error and I'm not exactly sure what is wrong

covert gladeBOT
#

@serene rover

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

serene rover
keen obsidian
#

perhaps start by telling us the error

#

then, when you feel the urge to post code,post all of it, as text not a screenshot

serene rover
#

I just read the rules. Sorry, I will do so now

#

THE CODE:

import random

options = ['Rock', 'Paper', 'Scissors']
move = options[random.randint(0, 2)]
print(move)

def winner(py_move, human_move):
if py_move == human_move:
print("IT'S A TIE")
elif py_move == 'Rock' and human_move == 'Paper':
print("YOU WIN")
elif py_move == 'Paper' and human_move == 'Rock':
print("I WIN")
elif py_move == 'Scissors' and human_move == 'Rock':
print("YOU WIN")
elif py_move == 'Rock' and human_move == 'Scissors':
print("I WIN")
elif py_move == 'Paper' and human_move == 'Scissors':
print("YOU WIN")
elif py_move == 'Scissors' and human_move == 'Paper':
print("I WIN")

keen obsidian
#

it's less a rule and more a way of increasing the odds of a stranger helping you for free πŸ™‚

#

so I notice you've defined a function called "winner", but you never call it.

#

Are you sure that's your complete code?

serene rover
#

for the error msg i cant seem to find it. but it had to do with unexpected indentation

keen obsidian
#

well ... that means your indentation is wrong.

#

But since you haven't posted the code that caused the error (you've posted something else instead), I can't imagine how I could help.

serene rover
#

this was the same code that caused the error

#

im not sure if i accidently changed it

foggy cedar
#

smolrat just a heads up, you can past code with these on either side to make it in a block

keen obsidian
#

well I ran your code and didn't get the error.

foggy cedar
#

it's called a backtick. Here's your code ```import random

options = ['Rock', 'Paper', 'Scissors']
move = options[random.randint(0, 2)]
print(move)

def winner(py_move, human_move):
if py_move == human_move:
print("IT'S A TIE")
elif py_move == 'Rock' and human_move == 'Paper':
print("YOU WIN")
elif py_move == 'Paper' and human_move == 'Rock':
print("I WIN")
elif py_move == 'Scissors' and human_move == 'Rock':
print("YOU WIN")
elif py_move == 'Rock' and human_move == 'Scissors':
print("I WIN")
elif py_move == 'Paper' and human_move == 'Scissors':
print("YOU WIN")
elif py_move == 'Scissors' and human_move == 'Paper':
print("I WIN")```

covert gladeBOT
#

Hey @foggy cedar!

It looks like you pasted Python code without syntax highlighting.

Please use syntax highlighting to improve the legibility of your code and make it easier for us to help you.

To do this, use the following method:
```py
print('Hello, world!')
```

This will result in the following:

print('Hello, world!')```
You can **edit your original message** to correct your code block.
keen obsidian
#

so you accidentally fixed it when you pasted it to discord πŸ™‚

foggy cedar
#

This is an interesting implementation. Is it the whole program? How new are you to python? I'm new too and I made my own but with user inputs etc.

serene rover
#
import random
options = ['Rock', 'Paper', 'Scissors']
move = options[random.randint(0, 2)]

def winner(py_move, human_move):
    if py_move == human_move:
        print("IT'S A TIE")
    elif py_move == 'Rock' and human_move == 'Paper':
        print("YOU WIN")
    elif py_move == 'Paper' and human_move == 'Rock':
        print("WOMP WOMP I WIN")
    elif py_move == 'Scissors' and human_move == 'Rock':
        print("YOU WIN")
    elif py_move == 'Rock' and human_move == 'Scissors':
        print("WOMP WOMP I WIN")
    elif py_move == 'Paper' and human_move == 'Scissors':
        print("YOU WIN")
    elif py_move == 'Scissors' and human_move == 'Paper':
        print("WOMP WOMP I WIN")

winner(move, human_move)
#

I'm not sur ewhat to do about winner

keen obsidian
#

generate two moves, not one

#

then call "winner", passing both of them

serene rover
#

what do you mean

foggy cedar
#

you haven't created a human move

keen obsidian
#
options = ["Rock", "Paper", "Scissors"]
py_move = options[random.randint(0, 2)]
print(py_move)
human_move = options[random.randint(0, 2)]
print(human_move)

winner(py_move, human_move)
foggy cedar
#

you're passing a variable, but there's no input for human.

#

*I mean argument not variable

#

offby fixed it for you

serene rover
#

ohh makes sense

#

thanks

#

but it still gives me an error

#

let me send

foggy cedar
#

you might need to change names of the argument

#

he put "py_move" you put "move" as the first variable

serene rover
#

i think that was a mistake on my behalf

foggy cedar
serene rover
#

I just changed to py move

foggy cedar
#

it works now, right?

serene rover
#

its saying "winner" is not defined

foggy cedar
#

check your indentation

#

post the code again

serene rover
#
import random
winner(move, human_move)
options = ["Rock", "Paper", "Scissors"]
py_move = options[random.randint(0, 2)]
print(py_move)
human_move = options[random.randint(0, 2)]
print(human_move)

winner(py_move, human_move)

def winner(py_move, human_move):
    if py_move == human_move:
        print("IT'S A TIE")
    elif py_move == 'Rock' and human_move == 'Paper':
        print("YOU WIN")
    elif py_move == 'Paper' and human_move == 'Rock':
        print("WOMP WOMP I WIN")
    elif py_move == 'Scissors' and human_move == 'Rock':
        print("YOU WIN")
    elif py_move == 'Rock' and human_move == 'Scissors':
        print("WOMP WOMP I WIN")
    elif py_move == 'Paper' and human_move == 'Scissors':
        print("YOU WIN")
    elif py_move == 'Scissors' and human_move == 'Paper':
        print("WOMP WOMP I WIN")


#

this is how it is rn

bright garden
serene rover
#

oh wait i just noticed the move

#
import random
winner(py_move, human_move)
options = ["Rock", "Paper", "Scissors"]
py_move = options[random.randint(0, 2)]
print(py_move)
human_move = options[random.randint(0, 2)]
print(human_move)

winner(py_move, human_move)

def winner(py_move, human_move):
    if py_move == human_move:
        print("IT'S A TIE")
    elif py_move == 'Rock' and human_move == 'Paper':
        print("YOU WIN")
    elif py_move == 'Paper' and human_move == 'Rock':
        print("WOMP WOMP I WIN")
    elif py_move == 'Scissors' and human_move == 'Rock':
        print("YOU WIN")
    elif py_move == 'Rock' and human_move == 'Scissors':
        print("WOMP WOMP I WIN")
    elif py_move == 'Paper' and human_move == 'Scissors':
        print("YOU WIN")
    elif py_move == 'Scissors' and human_move == 'Paper':
        print("WOMP WOMP I WIN")


bright garden
#

you call a function after defining it

foggy cedar
#

yeah functions **need to be defined ** before they're called lolol

bright garden
foggy cedar
#
winner(py_move, human_move)
options = ["Rock", "Paper", "Scissors"]
py_move = options[random.randint(0, 2)]
print(py_move)
human_move = options[random.randint(0, 2)]
print(human_move)

def winner(py_move, human_move):
    if py_move == human_move:
        print("IT'S A TIE")
    elif py_move == 'Rock' and human_move == 'Paper':
        print("YOU WIN")
    elif py_move == 'Paper' and human_move == 'Rock':
        print("WOMP WOMP I WIN")
    elif py_move == 'Scissors' and human_move == 'Rock':
        print("YOU WIN")
    elif py_move == 'Rock' and human_move == 'Scissors':
        print("WOMP WOMP I WIN")
    elif py_move == 'Paper' and human_move == 'Scissors':
        print("YOU WIN")
    elif py_move == 'Scissors' and human_move == 'Paper':
        print("WOMP WOMP I WIN")

winner(py_move, human_move)```
covert gladeBOT
#

Hey @foggy cedar!

It looks like you pasted Python code without syntax highlighting.

Please use syntax highlighting to improve the legibility of your code and make it easier for us to help you.

To do this, use the following method:
```py
print('Hello, world!')
```

This will result in the following:

print('Hello, world!')```
You can **edit your original message** to correct your code block.
bright garden
foggy cedar
#

lol I didn't even see that there

#
options = ["Rock", "Paper", "Scissors"]
py_move = options[random.randint(0, 2)]
print(py_move)
human_move = options[random.randint(0, 2)]
print(human_move)

def winner(py_move, human_move):
    if py_move == human_move:
        print("IT'S A TIE")
    elif py_move == 'Rock' and human_move == 'Paper':
        print("YOU WIN")
    elif py_move == 'Paper' and human_move == 'Rock':
        print("WOMP WOMP I WIN")
    elif py_move == 'Scissors' and human_move == 'Rock':
        print("YOU WIN")
    elif py_move == 'Rock' and human_move == 'Scissors':
        print("WOMP WOMP I WIN")winner
    elif py_move == 'Paper' and human_move == 'Scissors':
        print("YOU WIN")
    elif py_move == 'Scissors' and human_move == 'Paper':
        print("WOMP WOMP I WIN")

winner(py_move, human_move)```
bright garden
#

also its better to check for one person win and use else statement for other instead of checking .

serene rover
#

Oh I see but it was the winner function that I didn't define first correct?

serene rover
foggy cedar
#

no not you didn't define it, you called it before it was defined - which is a no no.

#

you can't call a function that doesn't exist yet and the interpereter/computer reads the code, from top to bottom.

#

so if you call a function - it needs to be defined prior to being called.

bright garden
serene rover
#

alr

#
import random
options = ["Rock", "Paper", "Scissors"]
py_move = options[random.randint(0, 2)]
print(py_move)
human_move = options[random.randint(0, 2)]
print(human_move)

def winner(py_move, human_move):
    if py_move == human_move:
        print("IT'S A TIE")
    elif py_move == 'Rock' and human_move == 'Paper':
        print("YOU WIN")
    elif py_move == 'Paper' and human_move == 'Rock':
        print("WOMP WOMP I WIN")
    elif py_move == 'Scissors' and human_move == 'Rock':
        print("YOU WIN")
    elif py_move == 'Rock' and human_move == 'Scissors':
        print("WOMP WOMP I WIN")
    elif py_move == 'Paper' and human_move == 'Scissors':
        print("YOU WIN")
    else:
        print("WOMP WOMP I WIN")

winner(py_move, human_move)
#

the only problem im facing is that

#

when I run the code

#

I can't write my own answer

#

it's randomly chosen

#

I think I need to add another variable

bright garden
foggy cedar
#

you could make another function, that returns the choice of the user.

#

using input() as Spark states

bright garden
# serene rover ```py import random options = ["Rock", "Paper", "Scissors"] py_move = options[ra...
import random
options = ["Rock", "Paper", "Scissors"]
py_move = options[random.randint(0, 2)]
print(py_move)
human_move = options[random.randint(0, 2)]
print(human_move)

def winner(py_move, human_move):
    if py_move == human_move:
        print("IT'S A TIE")
    elif py_move == 'Rock' and human_move == 'Paper':
        print("YOU WIN")
    elif py_move == 'Scissors' and human_move == 'Rock':
        print("YOU WIN")
    elif py_move == 'Paper' and human_move == 'Scissors':
        print("YOU WIN")
    else:
        print("WOMP WOMP I WIN")

winner(py_move, human_move)
#

this is what i meant

serene rover
#

That seems less time consuming to write

#

ty

foggy cedar
bright garden
serene rover
#
import random
human_move = input("Enter your move (Rock, Paper, or Scissors): ")
options = ["Rock", "Paper", "Scissors"]
py_move = options[random.randint(0, 2)]
print(py_move)
human_move = options[random.randint(0, 2)]
print(human_move)

def winner(py_move, human_move):
    if py_move == human_move:
        print("IT'S A TIE")
    elif py_move == 'Rock' and human_move == 'Paper':
        print("YOU WIN")
    elif py_move == 'Scissors' and human_move == 'Rock':
        print("YOU WIN")
    elif py_move == 'Paper' and human_move == 'Scissors':
        print("YOU WIN")
    else:
        print("WOMP WOMP I WIN")

winner(py_move, human_move)
#

guys if I put it at the wrong spot

serene rover
foggy cedar
#

dude it's still printing "human move" as if it were randomly picked.

#

so remove this: human_move = options[random.randint(0, 2)]

#

personally, I'd do this

#
human_move = options[human_choice-1]
serene rover
#

I can't thank you enough 😭😭

#

sorry for the trouble

#

I started learning 3 days ago which is why I'm dumb in python

#

I'm not sure if you suggest anything

#

to help speed up my learning etc.

deep trail
#

!resources

covert gladeBOT
#
Resources

The Resources page on our website contains a list of hand-selected learning resources that we regularly recommend to both beginners and experts.

foggy cedar
#

Reading code, go slowly lol

#

Part of coding is also developing the problem solving mind set. It takes time.

covert gladeBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.