#πŸ”’ Constant Indent error

25 messages Β· Page 1 of 1 (latest)

kind harbor
#

do not know what to do to fix this indent error and I feel like I have tried everything (on line 104) and gives the error: Traceback (most recent call last):
File "C:\Users\timot\Downloads\a3_skeleton (1).py", line 104
if text_choice == 1:
^
IndentationError: unindent does not match any outer indentation level

fluid oracleBOT
#

@kind harbor

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.

kind harbor
#

here is the code in text: if text_choice == 1:
sentences = []
for paragraph in data:
paragraph_sentences = [s.strip() for s in paragraph.split(".") if len(s.strip()) > 5]
sentences.extend(paragraph_sentences)
print(f"Enter the sentence number you want (0-{len(sentences)-1}):")
choice = int(input())
elif text_choice == 2:
print(f"Enter the paragraph number you want (0-{len(data)-1}):")
choice = int(input())
elif text_choice == 3:
choice = 0
else:
print("Invalid text selection")
return

#

Constant Indent error

somber galleon
kind harbor
#

got it, still gives an error at line 104

#

and I can't wrap my head around why

somber galleon
lyric ridge
#

I suspect you just over indented the if at the top. Anyway, everything at that level needs the same indent, whatever indent you use.

#

i.e. all the if/elif/else need to line up, and they need the same indent as the words = etc which follow.

#

@kind harbor ^^

fluid oracleBOT
kind harbor
somber galleon
#

Please press the βœ… to upload your file to the pastebin, otherwise I can’t view it on my phone :)

kind harbor
#

should be accessible

somber galleon
#

You are having issues at 104 since the if has an extra space or two of indentation compared to the rest of the code

#

That applies to all the code below 104

#

If you are using an editor, you should be able to fix it by selecting it all and pressing shift + tab

#

104-134

kind harbor
#

yeah it did thatnks a bunch I was stuck on that for way too long

somber galleon
#

πŸ‘ since python is indentation based, you have to be careful, especially when pasting code. If all is good, !close to close this post

kind harbor
#

!close

fluid oracleBOT
#
Python help channel closed with !close

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.