Hello. I am trying to make a rock paper scissors game with what I have learned and this is my 4th day. However, even though I tried many ways, I couldn't manage the actual winning and losing logic in the rock paper scissors game. It only works sometimes mathematically — sometimes it wins, sometimes it loses. Do you have any suggestions for this? Where might I have made a mistake?
#🔒 I'm a python learner 4th day.
108 messages · Page 1 of 1 (latest)
@chrome ibex
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.
Closes after a period of inactivity, or when you send !close.
Can you copy/paste the code as text please? Screenshots are hard on the eyes, and we can't copy/paste code from them.
!code
In a game of rock paper scissors, both participants should have the same choices.
oyun_secenekleri = [rock,paper,scissors]
player_secim = int(input("Taş için 0 , Kağıt için 1 , Makas için 2 seçiniz"))
bot_secim = random.randint(-3, -1)
if bot_secim > player_secim :
print(oyun_secenekleri [player_secim] + oyun_secenekleri [bot_secim] + "Kaybettin.")
elif bot_secim < player_secim :
print(oyun_secenekleri [player_secim] + oyun_secenekleri [bot_secim] + "Kazandın")
else:
print(oyun_secenekleri [player_secim] + oyun_secenekleri [bot_secim] + "Berabere")
Read the embed to learn how to format your pasted code
Thank you. Can you edit that to put a ```py up the top and a ``` line down the bottom please?
```py
your code
goes here
```
Meanwhile:
Surely this line raises an error?
oyun_secenekleri = [rock,paper,scissors]
because there are no variables named rock paper or scissors ?
Everybody starts knowing nothing. No problem.
No. It's works I'm running codes and I'm selecting 0,1 or 2 always out "kazandın"
Your if-statment logic assumes that the choices are all in order. But 2 is supposed to test as < 0 because they wrap around to the beginning.
Not writing you lose or draw*
Can you tell me what your possible choices are for the bot?
So: 0 < 1 and 1 < 2 but 2 is supposed to be "less than 0" but arithmetically it is not.
bot_secim = random.randint(-3, -1)```
that's not what you have in the code you shared above
I changed rn
Ok, but do you also understand what cameron is saying about the order?
Yes thank you very much for helping
Can you show the updated code?
I'm updating 1min
Oh, did I show you the last version I made of the TicTacToe?
Nope, but feel free to open a help thread to share it there 🙂
I just have 1 problem, displaying to the terminal what I want. It's playable but I miss some little stuff
I'll do tomorrow
Today I'll study for college instead of Python
I want to see OPs code
I looked at the code as it is and didn’t understand it :/
But didn't you write it yourself?
Can you explain what the current problem is?
I write it myself
Then what are you missing?
The problem is that it keeps saying I always win. And in the rock-paper-scissors game, how should I handle the ranking for something like rock > scissors? Right now I’m just using randint with values like 0, 1, 2.
its rock
I’m a beginner and it’s only my fourth day, so I don’t have much experience yet. That’s why I’m having a bit of difficulty explaining
Dw, I've been there too, I'm a beginner myself. :3
1 ?
what beats 1?
2
and what beats 2?
3
oh sorry
Rock = 0
Paper = 1
Scissor = 2 ?
0 beat 2 2 beat 1 1 beat 0
am i right ?
Would it be correct to do this using an if statement?
yes, but we need to first figure out exactly what we're trying to say
we want to say "if the bot's number is 1 higher than the player, the bot wins"
but, we need to make sure to handle the bot's number not going to 3
if player+1 equals 3, then we actually want to say 0 instead
does that make sense?
yes thank you
ok, so we can do this a few different ways
let's start with a way you could do this without having to introduce new things to you
you can create another variable for this value
the value of this variable is the player + 1
and if that result makes it 3, then make it 0 instead. Can you think of an if to do that?
hehe, I made it too, I want to compare after op.
I guess yes
Give it a try
Why are we using numbers instead of strings in this case?
This is actually preferable. We only care about their positions, not the actual text
It's easier to compare numbers as a secuence than to compare each string individually

My English is a bit bad, sorry about that, but I had an idea. I’m sorry in advance if I upset you.
I thought about what you said about the 0, 1, 2 part, and I was thinking of beats them.
(player_secim == 0 and bot_secim == 2)
so you could do this, yes
you would need 1 condition for each possible win scenario (3 possibilities)
I’m going to try putting the possible outcomes like this in the elif part, add ‘you drew’ in the if part, and write ‘you lost’ in the else part.
should i add or
you could if you want to do it all in 1 line
always start by trying it and seeing what happens
we learn how to code by writing code and making mistakes
oyun_secenekleri = [rock,paper,scissors]
player_secim = int(input("Taş için 0 , Kağıt için 1 , Makas için 2 seçiniz"))
bot_secim = random.randint(0, 2)
if bot_secim > player_secim :
print(oyun_secenekleri [player_secim] + oyun_secenekleri [bot_secim] + "draw")
elif(player_secim == 0 and bot_secim == 2) or \
(player_secim == 1 and bot_secim == 0) or \
(player_secim == 2 and bot_secim == 1):
print(oyun_secenekleri [player_secim] + oyun_secenekleri [bot_secim] + "you win")
else:
print(oyun_secenekleri [player_secim] + oyun_secenekleri [bot_secim] + "You lose")```
Hey @chrome ibex!
Please edit your message to use a code block
Add a py after the three backticks.
```py
print('Hello, world!')
```
This will result in the following:
print('Hello, world!')```
I'm changing to english from turkish
you no longer need the > comparison if you're going to be doing all the == comparisons too
ahh I thought it might be turkish
merhaba 🙂
you can start by checking if both are equal, then you know for sure it's a draw
then you can check if the bot's number is 1 higher than the player's number
if it is, the bot wins, otherwise, the player wins
it's much easier to rule things out that way
Yes, it works in every case and the result is exactly what I wanted. Thank you very much.
And tomorrow I will review all the code I wrote again and look at my mistakes in a different way
you're welcome!
This help channel has been closed. 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.