#๐ h
188 messages ยท Page 1 of 1 (latest)
@simple widget
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.
Hey eivl
post the code again for reference
Okay
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
thanks. lets start from the beginning
lets say you want to check if one thing is true or false
Okay
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
Yes
what is wrong with this check?
Nothing
does it work?
It will print the two stribgs are not equal
so it will never be True
Hm
Yessssss man
so the if check does nothing
Nah
the point of an if check is for it to be either True or False depending on the situation
Hm
i could just replace all those lines of code with this
print('the two strings are not equal')
Hm
hey
the 1st if statement seems logically incorrect
when you do
if 'hi' and 'hello'=='hello'
print('False')
it will print true
please fix that
Yeah i studied it todaybso sorry man
we are talking about this here for a reason
xd
so does Hm mean yes?
im still waiting for a real resonse @simple widget
Yes
i see.. lets continue
if you compare a number with a string, would that number ever be equal to a string?
I think its not possible
i would agree
It will provide u a error
no i mean, what do you mean by that?
no, its just False
Yes
Its false yeah
so what did you mean by this? what do you want that check to do?
you are pointing to eivl and Starman and expecting the two names to be equal
They both are not equal it will return u a false
your function is called game over, so im guessing it checks some game state
but they will never be equal, they cannot be, so the check is pointless
Yess i sm building tic tac toe
and what does the numbers mean?
but they are not position, they are just numbers
So it hsve 9 squares
Yes
so the numbers will never be strings
Yes
you need variables that change if you want to check if that variable has a value or not
Ah finaaly man
Thank u so much now i got what i was tryinh to do and what is happeing there
this is a help session, you can ask me about things later
ok
if you used variables instead, this code would still not work 1 and 2 and 3 and 4 and 5 and 6 and 7 and 8 and 9 != ' '
you are only doing one equality check here
Ah i forgotten these things i was in my imaginary world
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.")
favorite_fruit == 'grapefruit' or 'lemon' is incorrect
favorite_fruit == 'grapefruit' or favorite_fruit == 'lemon' is correct
see the difference?
Okay u were told me this for first if statement
Got it msn but i hsvr s query
ask away
I got it this that i was doing illogical code but i dont know how can i make the position , those are just numbers
how do you store the game board state?
I had been not did it yet i just use for loop to create a table
show me the table
a list is a perfect way to store your game board state
thats what i would use
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
How can i store them
there are many ways, what was your plan?
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
i see.. but how are you going to store the board?
Honestly i had not any idea to store them
i ask because that is the only important detail of this
what are your options?
could you use a string?
Hm
My plan was to ask the user for column and row and print that
Just
well, do you know a datastructure that lets you access rows and columns?
Nah
so what are your options?
you must use one that you know
i cant just recommend you something unfamiliar and hard
Rows and columns
you can use for loops?
but lets think about my question above, could you use a string?
to be honest, you can use any datatype, but lets unpack this a bit
Okay unpack it
i have asked you one question twice now
What was that question string
could you use a string to store the game data?
This one
yes
Can i use list
i would argue that you should use a list
and not use a STRING
strings are immutable, and lists are mutable
do you know what those words mean?
We can make change
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
Datatyoe mesnsnfor loop?
how could you make rows and columns using lists?
Um.....
no, datatype is int str list float tuple and so on
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
Hm
so, if you want to use rows and columns, how can you do that?
Cam i use fumctions of list
Indexing
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
could you use more then one list?
So this list should have a variable
More than one yed
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?
board[1][1]
indexing starts at 0
Is it right now?
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 ?
Ok now my game had been complted
I got it man
great
Thanks a lot man
my pleasure
I appreciate your work
close this channel once you are done with it!
Oh btw
You should not check each position manually
You should do it automatically with a loop
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.