#๐Ÿ”’ h

188 messages ยท Page 1 of 1 (latest)

simple widget
#

Help

patent relicBOT
#

@simple widget

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.

prisma crypt
#

hey

#

it was for me

simple widget
#

Hey eivl

prisma crypt
#

post the code again for reference

simple widget
#

Okay

simple widget
# prisma crypt post the code again for reference


def game_is_over:
    if (1 and 2 and 3 and 4 and 5 and 6 and 7 and 8 and 9 !=  ' '):
        print('game finished')
    if [[1 and 2 and 3 == 'x' ] or [1 and 4 and 7 == 'x'] or [2 and 5 and 8 == 'x'] or [3 and 6 and 9 == 'x'] or [4 and 5 and 6 == 'x'] or [7 and 8 and 9== 'x'] or [1 and 5 and 9 == 'x'] [3 and 5 and 7 == 'x']]:
         print('x won')


#

Here is it

prisma crypt
#

thanks. lets start from the beginning

#

lets say you want to check if one thing is true or false

simple widget
#

Okay

prisma crypt
#
if 'hello' == 'world':
    print('hello is equal to world, this must be wrong')
else:
    print('the two strings are not equal')
#

we can do something like this

simple widget
#

Yes

prisma crypt
#

what is wrong with this check?

simple widget
#

Nothing

prisma crypt
#

does it work?

simple widget
#

It will print the two stribgs are not equal

prisma crypt
#

so it will never be True

simple widget
#

Hm

simple widget
prisma crypt
#

so the if check does nothing

simple widget
#

Nah

prisma crypt
#

the point of an if check is for it to be either True or False depending on the situation

simple widget
#

Hm

prisma crypt
#

i could just replace all those lines of code with this

#
print('the two strings are not equal')
simple widget
#

Hm

acoustic needle
simple widget
prisma crypt
feral flower
#

xd

prisma crypt
#

im still waiting for a real resonse @simple widget

prisma crypt
#

if you compare a number with a string, would that number ever be equal to a string?

prisma crypt
simple widget
#

It will provide u a error

prisma crypt
#

3 == 'x' so what does this mean?

#

3 will never be equal to the string 'x'

simple widget
#

Syntax error

prisma crypt
prisma crypt
simple widget
prisma crypt
simple widget
#

Its false yeah

prisma crypt
#

so what did you mean by this? what do you want that check to do?

simple widget
#

My mind had been blown

#

Its illogical thing man

#

Who can think like this

prisma crypt
#

you are pointing to eivl and Starman and expecting the two names to be equal

simple widget
prisma crypt
#

your function is called game over, so im guessing it checks some game state

prisma crypt
simple widget
#

Yess i sm building tic tac toe

prisma crypt
simple widget
#

There are s grid of 3 by 3

prisma crypt
simple widget
#

So it hsve 9 squares

prisma crypt
simple widget
#

Yes

prisma crypt
#

you need variables that change if you want to check if that variable has a value or not

simple widget
#

Ah finaaly man

#

Thank u so much now i got what i was tryinh to do and what is happeing there

feral flower
#

eivl

#

what is a one way trip in python?

prisma crypt
feral flower
#

ok

prisma crypt
#

you are only doing one equality check here

simple widget
prisma crypt
#

and that is 9 != ' '

#

!or-gotcha

patent relicBOT
#
The or-gotcha

When checking if something is equal to one thing or another, you might think that this is possible:

# Incorrect...
if favorite_fruit == 'grapefruit' or 'lemon':
    print("That's a weird favorite fruit to have.")

While this makes sense in English, it may not behave the way you would expect. In Python, you should have complete instructions on both sides of the logical operator.

So, if you want to check if something is equal to one thing or another, there are two common ways:

# Like this...
if favorite_fruit == 'grapefruit' or favorite_fruit == 'lemon':
    print("That's a weird favorite fruit to have.")

# ...or like this.
if favorite_fruit in ('grapefruit', 'lemon'):
    print("That's a weird favorite fruit to have.")
prisma crypt
#

favorite_fruit == 'grapefruit' or 'lemon' is incorrect

#

favorite_fruit == 'grapefruit' or favorite_fruit == 'lemon' is correct

#

see the difference?

simple widget
simple widget
prisma crypt
#

ask away

simple widget
#

I got it this that i was doing illogical code but i dont know how can i make the position , those are just numbers

prisma crypt
simple widget
prisma crypt
#

show me the table

#

a list is a perfect way to store your game board state

#

thats what i would use

simple widget
#

print('its a tic tac toe')

for i in range(3):
    print('_______|' *3)

#

Here it is

prisma crypt
#

you are missing a way to store the game state, what is your plan to do that?

#

game state just means where all the X and O are located

simple widget
#

How can i store them

prisma crypt
simple widget
#

How to chage user im tic tac toe i am foinh like this but it is not a good way


print('its a tic tac toe')

def changeuser():
    if user == 'X':
        user =='0'
    elif user == '0':
        user=='X'

Btw This was my function to change user

prisma crypt
#

i see.. but how are you going to store the board?

simple widget
prisma crypt
#

i ask because that is the only important detail of this

prisma crypt
#

could you use a string?

simple widget
#

Hm

simple widget
#

Just

prisma crypt
prisma crypt
#

you must use one that you know

#

i cant just recommend you something unfamiliar and hard

simple widget
#

Rows and columns

feral flower
prisma crypt
#

but lets think about my question above, could you use a string?

simple widget
#

For loop

#

?

prisma crypt
#

to be honest, you can use any datatype, but lets unpack this a bit

simple widget
#

Okay unpack it

prisma crypt
simple widget
#

What was that question string

prisma crypt
#

could you use a string to store the game data?

prisma crypt
#

yes

simple widget
prisma crypt
#

and not use a STRING

#

strings are immutable, and lists are mutable

#

do you know what those words mean?

simple widget
#

Yeah

#

Change

prisma crypt
#

yes

#

the game will change every round

simple widget
#

We can make change

prisma crypt
#

so you should store your game state in a datatype that can change

#

a list is perfect for that

#

is you make one list, you would not be able to get row and columns

simple widget
prisma crypt
#

how could you make rows and columns using lists?

simple widget
prisma crypt
prisma crypt
#

it is the type of the data you want to store

#

the number one can be written 1 1.0 '1'

#

same numer, differnt datatype

simple widget
#

Hm

prisma crypt
#

so, if you want to use rows and columns, how can you do that?

simple widget
#

Indexing

prisma crypt
#

ofc, thats why you use lists, because they have behaviour you can use

#

['', '', '', '', '', '', '', '', ''] you can have one list

#

but this does not give you row and columns

#

it gives you index 0-9

simple widget
#

Hm then how can i get

#

Hm

prisma crypt
simple widget
prisma crypt
#

each row could be a list of its own maybe

#

maybe like this?

simple widget
prisma crypt
#

board[0][0] would be the first row and first position in that row

#

dont get sidetracked

#

how would you assign 'X' to the middle possition in this board?

prisma crypt
prisma crypt
simple widget
#

Sorry man

simple widget
prisma crypt
#

yes,. no worries. so board[1][1] = 'X' would assign the middle possition

#
[['', '', ''],
 ['', 'X', ''],
 ['', '', '']]

#

so if you use lists to save the possitions of your game you can do all the checks you need

#

do you have enough info to continue ?

simple widget
#

Ok now my game had been complted

simple widget
prisma crypt
#

great

simple widget
#

Thanks a lot man

prisma crypt
#

my pleasure

simple widget
#

I appreciate your work

prisma crypt
#

close this channel once you are done with it!

simple widget
#

Ok i will create it in 2 to 3 hours

#

And will close it

merry zephyr
#

Oh btw

#

You should not check each position manually

#

You should do it automatically with a loop

patent relicBOT
#
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.