hy. When i run this code on shell it gives me an error of unindent does not match any outer indentation level....how to handle t | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

hy. When i run this code on shell it gives me an error of unindent does not match any outer indentation level....how to handle t

def max(x, y): if x>y: return x else: return y print(max(7, 9)) grt=max(x, y) print (grt)

10th May 2017, 11:50 AM
Shah Zaib
Shah Zaib - avatar
2 Answers
+ 5
@Kyle Broflovski is right for last two lines, but block inside the function is indented ( of only once space before the if )... Unfortualy, in the question author version, the print() line is also indented with one space, so it's considered as in the function block :P So, @Kyle solution is ok for fix the indentation error, but anyway, the line: grt=max(x, y) ... will throw an undeclared variable error ( unless some values were assigned to 'x' and 'y' somewhere before in a part of code not provided ^^ )
10th May 2017, 12:39 PM
visph
visph - avatar
+ 2
your grt and print at the bottom are indented and your if statement inside your function isn't. inside if/else get 4 space indent.. inside function also get 4 space indent. def max(x, y): if x>y: return x else: return y print(max(7, 9)) grt=max(x, y) print (grt)
10th May 2017, 11:52 AM
LordHill
LordHill - avatar