#๐Ÿ”’ whats wrong with this code?

84 messages ยท Page 1 of 1 (latest)

teal trenchBOT
#

@nocturne mirage

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.

nocturne mirage
#

!paste

teal trenchBOT
#
Pasting large amounts of code

If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/

After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.

nocturne mirage
#

!paste

#

you guys see it?

stray karma
#

Yea, is there any error?

nocturne mirage
#

yes

raven ingot
#

!traceback

teal trenchBOT
#
Traceback

Please provide the full traceback for your exception in order to help us identify your issue.
While the last line of the error message tells us what kind of error you got,
the full traceback will tell us which line, and other critical information to solve your problem.
Please avoid screenshots so we can copy and paste parts of the message.

A full traceback could look like:

Traceback (most recent call last):
  File "my_file.py", line 5, in <module>
    add_three("6")
  File "my_file.py", line 2, in add_three
    a = num + 3
        ~~~~^~~
TypeError: can only concatenate str (not "int") to str

If the traceback is long, use our pastebin.

noble arrow
# nocturne mirage yes

You have to give people all the information they might need all at onceyou have to give people all the information they might need all at once

nocturne mirage
#

okay

#

i cant send pics tho

#

of the error

#

oh i can

noble arrow
#

You can copy and paste it as text

nocturne mirage
#

thats the error

noble arrow
#

That's fine for now, but remember to always give text as actual text.

nocturne mirage
#

it didnt let me copy it idk why

dire light
# nocturne mirage

Seems you didn't save your file? The python interpreter sees the 10th line as cut, saying it ends with dtype=in

#

Instead of dtype=int)

noble arrow
#

Yeah. And you can't have "in" as a name/variable

#

Which is why you're getting a syntax error instead of a name error

dire light
nocturne mirage
#

im not a coder at all i have no idea what im doing im just trying to make a game lmao

nocturne mirage
dire light
nocturne mirage
#

still same

#

i saved it

dire light
#

If it's saved but still shows the same error, make sure a cat didn't sit on your keyboard - the code you posted in the pastebin shouldn't have this error, but accidental enter on 10th line would cause this error

#

Just make sure the code on 10th line matches the code of 10th line in the pastebin earlier

timid wing
#

Well, look at line 175. It's very misaligned.

nocturne mirage
#

ah i see

#

idk what to do

#

where you able to run the code?

#

the exact code pasted

timid wing
#

What is line 175 meant to be inside of?

#

The if block above it?

nocturne mirage
dire light
teal trenchBOT
#
Indentation

Indentation is leading whitespace (spaces and tabs) at the beginning of a line of code. In the case of Python, they are used to determine the grouping of statements.

Spaces should be preferred over tabs. To be clear, this is in reference to the character itself, not the keys on a keyboard. Your editor/IDE should be configured to insert spaces when the TAB key is pressed. The amount of spaces should be a multiple of 4, except optionally in the case of continuation lines.

Example

def foo():
    bar = 'baz'  # indented one level
    if bar == 'baz':
        print('ham')  # indented two levels
    return bar  # indented one level

The first line is not indented. The next two lines are indented to be inside of the function definition. They will only run when the function is called. The fourth line is indented to be inside the if statement, and will only run if the if statement evaluates to True. The fifth and last line is like the 2nd and 3rd and will always run when the function is called. It effectively closes the if statement above as no more lines can be inside the if statement below that line.

Indentation is used after:
1. Compound statements (eg. if, while, for, try, with, def, class, and their counterparts)
2. Continuation lines

More Info
1. Indentation style guide
2. Tabs or Spaces?
3. Official docs on indentation

nocturne mirage
#

i dont really know what this i supposed to mean

dire light
#

Please read this embed

#

It literally explains what indentation is and what purpose it serves

nocturne mirage
#

i dont know any of these terms lmao

#

i have never coded before

dire light
nocturne mirage
#

are you able to do it?

#

change the issue?

nocturne mirage
timid wing
nocturne mirage
#

oh

#

im not sure. chatgpt wrote it for me

#

im trying to make a 5 in a row game

#

against an ai

#

Certainly! Below is an implementation of a Connect 5 game on a 7x9 board in Python. I'll also include a simple AI opponent using a basic minimax algorithm with alpha-beta pruning.

#

This code sets up a Connect 5 game on a 7x9 board, with you playing against a simple AI opponent that uses a minimax algorithm with alpha-beta pruning to select its moves. You can play as "Player 1" and the AI will be "Player 2". The game will prompt you to make a selection (0-8) for your move. The AI will automatically make its move afterward.

#

thats what they said

#

and with all that code

nocturne mirage
raven ingot
#

People aren't going to want to debug ChatGPT code. The problem with using ChatGPT to write code you don't understand is (as you have now experienced) not knowing how to fix what it messes up.

nocturne mirage
#

right

nocturne mirage
timid wing
nocturne mirage
#

im jusst tryna play 5 in a row

#

doing my best

#

appricate all the time you give

timid wing
#

It would be better to learn for yourself.

nocturne mirage
#

i just wanna play 5 in a row

#

against a super strong ai

#

on a 7x9 board

#

sadly it doesnt exist

#

so im trying to make it

nocturne mirage
#

but the issue is the ai doesnt even play

teal trenchBOT
#
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.