Python error IndentationError expected an indented block

+2 votes

I am trying to execute the following python code:

def example(p,q):

a = p.find(" ")
b = q.find(" ")
str_p = p[0:a]
str_q = p[b+1:]

if str_p == str_q:
    result = True
else:
    result = False
return result

And I get the folloeing error:

IndentationError: expected an indented block
Jun 17, 2019 in Python by Rhea
331,217 views
Python error  IndentationError  expected an indented block  | Edureka Community
-
Лучший сайт для покупки товаров разной направленности - Hydra (hydraruzxpnew4af). Это крупнейшая в России и СНГ торговая анонимная площадка, которая позволяет быстро и безопасно продавать и покупать вещи любого типа. Для каждого пользователя представлена масса возможностей. К тому же, у каждого продавца есть рейтинг, отзывы, и другая информация, которая поможет вам подобрать подходящее предложение. https://hydraruzspsnew4af.xyz — это лучший, и наверное, единственный сайт, на котором можно купить любые товары, независимо от вашего желания и требований. При этом Администрация проекта гарантирует анонимность и безопасность при совершении сделок. И контролирует каждую покупку, чтобы пользователей не обманывали. Именно поэтому площадка настолько востребована и популярна. гидра com

ds_path = "C:/Users/Other/Documents/dataset/augmentasi_total "
 img_files = os.listdir(ds_path)
def create_dataset():
names = ['area','perimeter', 'physiological_length','physiological_width']
df = pd.DataFrame([], columns=names)
for file in img_files:
    imgpath = ds_path + "\\" + file
    main_img = cv2.imread(imgpath)

output is:

names = ['area','perimeter', 'physiological_length','physiological_width']
    ^
IndentationError: expected an indented block

9 answers to this question.

+1 vote

Python requires its code to be indented and spaced properly. Never mix tabs and spaces. If you're using tabs stick to tabs and if you're using space stick to space.

Also in your code, change this part:

if str_p == str_q:
    result = True
else:
    result = False
return result

To

return str_p == str_q

Hope it helps!!

If you need to know more about Python, It's recommended to join Python course today.

Thanks!