#๐Ÿ”’ I need help

123 messages ยท Page 1 of 1 (latest)

hidden arrow
#

Why I am keep getting this error?

Code:

    while True:
        amount = input("What would you like to deposit? $")  
        if amount.isdigit():
            amount = int(amount)
            if amount > 0:
                break
            else:
                print("Amount must be greater than 0.")
        else:
            print("Please enter a number.")

    return amount ```





Output:
```PS C:\Users\spongebob\Desktop\proje3> python3 .\main.py
  File "C:\Users\spongebob\Desktop\proje3\main.py", line 78
    else:
         ^
IndentationError: unindent does not match any outer indentation level
PS C:\Users\spongebob\Desktop\proje3>```
dense talonBOT
#

Hey @hidden arrow!

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!')```
dense talonBOT
#

@hidden arrow

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.

half wolf
#

did you mix tabs and spaces?

woeful mountain
hidden arrow
half wolf
#

if you used both tabs and spaces for indentation, that might trigger the error

hidden arrow
#

how do I check

#

i think I do

woeful mountain
hidden arrow
woeful mountain
#

There should be an option at the bottom to convert all to spaces

#

it's recommended to use 4 spaces instead of tabs

half wolf
#

this is from the PEP-8 style guide

#

you'll find the vast majority of publicly available code using the standard 4 space indent

hidden arrow
#

what is that

woeful mountain
#

PEP-8 is a guide outlining how python should be styled

#

it keeps things consistent

#

imagine working with other people and some of you use tabs and some of you use spaces, it would be a mess trying to share code

#

!pep8

dense talonBOT
#
PEP 8

PEP 8 is the official style guide for Python. It includes comprehensive guidelines for code formatting, variable naming, and making your code easy to read. Professional Python developers are usually required to follow the guidelines, and will often use code-linters like flake8 to verify that the code they're writing complies with the style guide.

More information:

hidden arrow
woeful mountain
#

no

#

a tab is represented as \t

#

!e

print('hello\tworld')
dense talonBOT
hidden arrow
#

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

dense talonBOT
hidden arrow
#

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

dense talonBOT
woeful mountain
#

even though they visually look the same, they are not the same

hidden arrow
#

!e ```py
print('Hello,\tworld!')

dense talonBOT
hidden arrow
#

i understand

#

thanks

hidden arrow
woeful mountain
#

they can be different sizes

hidden arrow
#

oh I see

woeful mountain
#

I still press the Tab button on my keyboard and it does 4 spaces

#

so it's not like you need to press space 4 times every time you want to indent

hidden arrow
#

that makes sense

hidden arrow
#

keybinds?

woeful mountain
woeful mountain
#

This is Sublime Text though

hidden arrow
woeful mountain
#

I mainly work with pycharm

#

sublime doesn't support input which is a bit of a pain

hidden arrow
#

that's cool

#

but how do I fix this code bro

#

do I just type spaces

#

there is still error

#

still same

#

@woeful mountain ??

half wolf
#

that looks like you have two else blocks in the same if...else structure

half wolf
#

the first else block looks like it needs to be indented more

#

or just drop the else and indent the following line

hidden arrow
#

like this?

#

@half wolf

#

oh my bad

#

what about this?

half wolf
#

do you see the red squiggly line?

hidden arrow
#

yeah

half wolf
#

this is exactly what you had when I told you to drop the else and indent the next line

#

so you changed nothing

hidden arrow
#

bro I am just beginner

#

how

half wolf
#

what do you mean "how"

#

you at least know how to edit code? delete lines etc.?

hidden arrow
half wolf
#

so do that?

hidden arrow
#

but can you be more clear

half wolf
#

delete the first else

#

and indent the line after

#

oh, wait, no need for the indent

#

it should already work as is after you delete the else

hidden arrow
#

like this?

half wolf
#

yup

hidden arrow
#

ill kms

half wolf
#

what happens if you delete lines 77 and 78?

hidden arrow
half wolf
#

looks like you forgot to save?

hidden arrow
#

no

#

i did

#

CTRL + S

half wolf
#

well, there's no elseon line 78

#

so what would it be complaining about?

#

are you sure you're editing the same file you're trying to run?

hidden arrow
#

wait its saved now

#

wtf

hidden arrow
#

now other error

half wolf
#

it would help if you showed us what's on the line the error refers to

hidden arrow
#

sorry here

half wolf
#

well, yeah, you can't have two else statements in the same if...else block

#

so you need to dedent the latter else block

hidden arrow
#

okay okay

#

i fixed but

#

wtf

half wolf
#

?

hidden arrow
#

there are 3 more errors

#

bro this is code is already from a youtube project video

#

should I copy the original file to here to fix all errors

half wolf
#

maybe?

hidden arrow
#

alright thanks

half wolf
#

use a pastebin if you intend to paste large amounts of code here

#

!paste

dense talonBOT
#
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.

hidden arrow
#

can I dm you for help?

half wolf
#

no

hidden arrow
#

alr

dense talonBOT
#
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.