Why am I Getting "Indentationerror: Expected an Indented Block"

Why am I getting IndentationError: expected an indented block?

As the error message indicates, you have an indentation error. It is probably caused by a mix of tabs and spaces.

How to fix IndentationError: expected an indented block in Python?

Problem is that you did not tell the program what to do when the first condition is satisfied (if statement). If you are not sure about what to do in if, you can use python build in 'pass'.

if page_response.status_code == 200:
pass
else:
print(page_response.status_code)

Why do I get IndentationError: expected an indented block

A doc string isn't a comment from the point of view of the parser. It's an ordinary expression statement, and as such must be indented like any other part of the def statement's body.

indentationerror expected an indented block function

You must add 4 spaces for indent.

def sesver():
r = sr.Recognizer()
with sr.Microphone() as source:
print("Bir sey de!")
audio = r.listen(source)
data = ""
try:
data = r.recognize_google(audio, language='tr-tr')
data = data.lower()
return data
except ValueError:
pass

data = sesver()

I am getting “IndentationError: expected an indented block” in np.random.seed(2). How to fix this?

Everything from:

def initialize_parameters(n_x, n_h, n_y):

to

return parameters

in your example above needs to be indented four spaces. I.e., this:

def initialize_parameters(n_x, n_h, n_y):

np.random.seed(2) # we set up a seed so that our output matches ours although the initialization is random.

W1 = np.random.randn(n_h, n_x) * 0.01 #weight matrix of shape (n_h, n_x)
b1 = np.zeros(shape=(n_h, 1)) #bias vector of shape (n_h, 1)
W2 = np.random.randn(n_y, n_h) * 0.01 #weight matrix of shape (n_y, n_h)
b2 = np.zeros(shape=(n_y, 1)) #bias vector of shape (n_y, 1)

#store parameters into a dictionary
parameters = {"W1": W1,
"b1": b1,
"W2": W2,
"b2": b2}

return parameters

should be formatted like this:

def initialize_parameters(n_x, n_h, n_y):

np.random.seed(2) # we set up a seed so that our output matches ours although the initialization is random.

W1 = np.random.randn(n_h, n_x) * 0.01 #weight matrix of shape (n_h, n_x)
b1 = np.zeros(shape=(n_h, 1)) #bias vector of shape (n_h, 1)
W2 = np.random.randn(n_y, n_h) * 0.01 #weight matrix of shape (n_y, n_h)
b2 = np.zeros(shape=(n_y, 1)) #bias vector of shape (n_y, 1)

#store parameters into a dictionary
parameters = {
"W1": W1,
"b1": b1,
"W2": W2,
"b2": b2
}

return parameters

(I threw in the parameters dictionary formatting as a bonus ;))

IndentationError: expected an indented block [Python]

May be it is due the editor or improper indentation.

Your code is perfectly running in my pc but I would suggest to run the below code

from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello_world():
return 'Hello World!'

if __name__ == '__main__':
app.debug = True
app.run(port=8080)


Related Topics



Leave a reply



Submit