#πŸ”’ Im new and i need help

45 messages Β· Page 1 of 1 (latest)

lavish void
#

I dont know what to do matter fact i dont know if my coding is even correct i think i js havw placed erong stuff

fallen elkBOT
#

@lavish void

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.

potent pilot
#

You've got an indentation error

#

Whenever you have a try: the bit after must be indented

#

this is on line 215

#

You've got a lot of try/except blocks. I'm not sure that is optimal

lavish void
#

So what should i do?

lavish void
# potent pilot ^

Yeah but how many times to i have to oress space mb if im anoying im new

potent pilot
#

four times usually

#

or tab

#

depends which one your code uses

lavish void
potent pilot
#

everything between the try up to the corresponding except

lavish void
#

Better?

potent pilot
#

run it and you tell me

lavish void
#

This now

potent pilot
#

you've got another indentation error

#

on line 221

#
try:
  something()
except:
  something()

# this is incorrect

try:
something()
except:
something()
#

sorry it was line 221

lavish void
#

So it is with if aswell?

potent pilot
#

i dont understand what you mean

#

yes

#

!indent

fallen elkBOT
#
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

potent pilot
#
Indentation is used after:
1. Compound statements (eg. if, while, for, try, with, def, class, and their counterparts)
lavish void
#

Is 221 correct

potent pilot
#

for all of these guys

#
if
while
for
try
with
def
class

etc

kind hornet
#

Damn u coding on u phone

lavish void
lavish void
potent pilot
#

yes but I see another problem

lavish void
potent pilot
#

so run the code, read the error traceback, and fix the mistake

lavish void
#

Thanks for being so patient btw

potent pilot
#

that looks better

lavish void
#

Yoooo it workssss

#

Thank you

potent pilot
#

nw

fallen elkBOT
#
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.