#🔒 I'm a python learner 4th day.

108 messages · Page 1 of 1 (latest)

chrome ibex
#

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?

vague pilotBOT
#

@chrome ibex

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.

mortal hollow
#

!code

vague pilotBOT
#
Formatting code on Discord

Here's how to format Python code on Discord:

```py
print('Hello world!')
```

These are backticks, not quotes. Check this out if you can't find the backtick key.

For long code samples, you can use our pastebin.

upper acorn
chrome ibex
#

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")
upper acorn
# vague pilot

Read the embed to learn how to format your pasted code

mortal hollow
chrome ibex
#

oh thank you sorry

#

I'm a little bit junior

mortal hollow
#

Meanwhile:

Surely this line raises an error?

oyun_secenekleri = [rock,paper,scissors]

because there are no variables named rock paper or scissors ?

mortal hollow
chrome ibex
mortal hollow
#

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.

chrome ibex
#

Not writing you lose or draw*

upper acorn
#

Can you tell me what your possible choices are for the bot?

mortal hollow
#

So: 0 < 1 and 1 < 2 but 2 is supposed to be "less than 0" but arithmetically it is not.

chrome ibex
#
bot_secim = random.randint(-3, -1)```
upper acorn
#

that's not what you have in the code you shared above

chrome ibex
upper acorn
#

Ok, but do you also understand what cameron is saying about the order?

chrome ibex
#

Yes thank you very much for helping

upper acorn
#

Can you show the updated code?

chrome ibex
#

I'm updating 1min

pseudo hill
upper acorn
pseudo hill
#

I just have 1 problem, displaying to the terminal what I want. It's playable but I miss some little stuff

pseudo hill
#

Today I'll study for college instead of Python

#

I want to see OPs code

chrome ibex
#

I looked at the code as it is and didn’t understand it :/

pseudo hill
upper acorn
#

Can you explain what the current problem is?

chrome ibex
pseudo hill
chrome ibex
upper acorn
#

think about which number beats what

#

what beats 0?

chrome ibex
#

its rock

upper acorn
#

I'm asking by position, not the actual name

#

what beats "whatever is in position 0"?

chrome ibex
# pseudo hill Then what are you missing?

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

pseudo hill
chrome ibex
upper acorn
chrome ibex
#

2

upper acorn
#

and what beats 2?

chrome ibex
#

3

upper acorn
#

are you sure?

#

we only have 0, 1, 2 as options. What is 3?

chrome ibex
#

oh sorry

pseudo hill
chrome ibex
#

am i right ?

upper acorn
#

exactly

#

that gives us a circle like so

#

wait my arrows are the wrong way

chrome ibex
#

Would it be correct to do this using an if statement?

upper acorn
upper acorn
#

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?

chrome ibex
#

yes thank you

upper acorn
#

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?

pseudo hill
#

hehe, I made it too, I want to compare after op.

upper acorn
#

Give it a try

cloud carbon
#

Why are we using numbers instead of strings in this case?

upper acorn
#

This is actually preferable. We only care about their positions, not the actual text

pseudo hill
chrome ibex
#

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)

upper acorn
#

so you could do this, yes

#

you would need 1 condition for each possible win scenario (3 possibilities)

chrome ibex
#

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.

upper acorn
#

and that's perfectly ok if it works for you

#

you can always start with a draw

chrome ibex
#

should i add or

upper acorn
#

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

chrome ibex
#

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")```
vague pilotBOT
#

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!')```
chrome ibex
#

I'm changing to english from turkish

upper acorn
#

you no longer need the > comparison if you're going to be doing all the == comparisons too

upper acorn
#

merhaba 🙂

chrome ibex
#

Now It's working.

#

You lose

upper acorn
#

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

chrome ibex
#

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

upper acorn
#

you're welcome!

vague pilotBOT
#
Python help channel closed for inactivity

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.