#π Not sure what's wrong
101 messages Β· Page 1 of 1 (latest)
@serene rover
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.
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
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")
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?
for the error msg i cant seem to find it. but it had to do with unexpected indentation
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.
this was the same code that caused the error
im not sure if i accidently changed it
smolrat just a heads up, you can past code with these on either side to make it in a block
well I ran your code and didn't get the error.
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")```
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.
so you accidentally fixed it when you pasted it to discord π
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.
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
what do you mean
you haven't created a 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)
you're passing a variable, but there's no input for human.
*I mean argument not variable
offby fixed it for you
you might need to change names of the argument
he put "py_move" you put "move" as the first variable
i think that was a mistake on my behalf
I just changed to py move
it works now, right?
its saying "winner" is not defined
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
ur calling the function before ur declaring the function
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")
you call a function after defining it
yeah functions **need to be defined ** before they're called lolol
think like your code moves from up to down
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)```
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.
there is one more func call on line 2
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)```
also its better to check for one person win and use else statement for other instead of checking .
Oh I see but it was the winner function that I didn't define first correct?
instead of elif I should use else?
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.
check if you are winning from the above 3 conditions and on last just put a else statement you dont need to check it again
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
that's not what i meant ...
you can use input()
you could make another function, that returns the choice of the user.
using input() as Spark states
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
big brain programmer move π
only 3 conditions are there 1. tie 2. py win 3. human win
you checked condition 1 on the first if statement
you checked condition 2 on the 3 elif statements after if
and now you dont need to check becuase condition 3 will be approved anyways
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
fr
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]
oh wow I forgot about that
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.
!resources
The Resources page on our website contains a list of hand-selected learning resources that we regularly recommend to both beginners and experts.
I'm a noob too, don't worry.
Reading code, go slowly lol
Part of coding is also developing the problem solving mind set. It takes time.
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.