-1

I don't know what's wrong exactly

I'm following someone explains how to create a simple bot by flask and Twilio

then when I'm running flask showing me this problem

"File "C:\Users\moham\Desktop\FLASK_APP\app.py", line 23 else: ^ IndentationError: unindent does not match any outer indentation level"

here was the problem is:

    def process_msg(msg):
  response = ""
  if msg == "hi": 
       response = "Hello, welcome to the stock market bot!"
    else:
       response = "Please type hi to get started."
    return response

It said line 23 !! in (else:)

I hope you understanding me!

thank you in advance

davidism
  • 121,510
  • 29
  • 395
  • 339
  • IndentationError just means that your Indentations arent alligned properly. Eg maybe your if is 1 tab indented and the else only 2 spaces. – Noah Nov 17 '20 at 14:35
  • Your `else` *doesn't* match the indentation of the associated `if` (or anything else that precedes it). The error is pretty clear. You need to dedent the `else` (and the `return`) to match the `if`. – ShadowRanger Nov 17 '20 at 14:35
  • Does this answer your question? [IndentationError: unindent does not match any outer indentation level](https://stackoverflow.com/questions/492387/indentationerror-unindent-does-not-match-any-outer-indentation-level) – Tomerikoo Nov 17 '20 at 15:01

1 Answers1

1

Your else has to be on the same indentation level as your if as python creates blocks by indentations and with different indentation levels it cant group the else and if into the same block leaving the else without an if.

def process_msg(msg):
  response = ""
  if msg == "hi": 
     response = "Hello, welcome to the stock market bot!"
  else:
     response = "Please type hi to get started."
  return response
Noah
  • 617
  • 5
  • 15