Beginner having ident issue with (if, else)

>>> furry = True
>>> large = True
>>> if furry:
	if large:
		print("It's a yeti.")
	else:
		print("It's a cat.")
     else:
	    
SyntaxError: unindent does not match any outer indentation level ```

Having trouble getting this to work on IDLE. Python v3.9. The book I am using to learn is based on v3.7.

Hi Mason,

I don’t normally use IDLE, so at first I was having trouble
understanding why you were having lining things up. But I just tried it,
and now I see why!

When you line up to the first line, you have to pretend the initial
>>> prompt is not there. That means what you see is this:

>>> if furry:
	if large:
		print("yeti")
	else:
		print("cat")

and so you think that you need to indent the next line to make it line
up with the if:

>>> if furry:
	if large:
		print("yeti")
	else:
		print("cat")
    else:  # needs four spaces to line up with the top "if"

but in fact, you have to pretend that you see this:

# pretend the >>> prompt isn't there
if furry:
	if large:
		print("yeti")
	else:
		print("cat")
else:  # actually lines up with the top "if"

If this seems weird to you, it seems weird to me too. As I mentioned, I
hardly ever use IDLE, and I have never come across this before. In the
regular Python (non-IDLE) interactive interpreter, if blocks print the
second-level prompt, so you see this:

>>> if furry:
...     if large:
...             print("yeti")
...     else:
...             print("cat")
... else:  # looks like it lines up with the top "if"

and there’s no need to “pretend” anything, it naturally lines up.

This is so strange I wonder if I am doing something wrong. Unless
somebody who understands IDLE better than me speaks up, I hope this
helps.

Mason, please edit your post to surround the code with two lines each with 3 backticks, ```, one line above and one line below the code. The backtick key should be the key to the left of the ‘1’ key, above Tab. This markup says that the lines in between are code. Until you do that, I cannot tell what you entered and what the error is.

Even with that, code cut and pasted from IDLE’s Shell will not quite look right because github does the code will have tab indents and tabs are not properly formated as 8 spaces. So I have replaced Tabs below with spaces. Below is how your code should look like in Shell correctly entered so that it runs. The indents are automatic.

>>> furry = True
>>> large = True
>>> if furry:
        if large:
                print("It's a yeti")
        else:
                print("It's a cat")
else:
        print("Neither yeti or cat")
	
It's a yeti

Steven, I agree that the use of tabs for indents, and the uneven left margin, are mis-features – one of the worst left in IDLE. You are correct that one should mentally remove the ‘>>>’ on the first line of a composite statement. We are working on a patch to fix this by moving the prompt into a marginal column, like with line numbers.

Thanks for the help.

I tried it as you suggested, as if the >>> was not there for the else command and it worked.

Thanks again

Thanks for the help.

I tried it as you suggested, as if the >>> was not there for the “if” command and it worked.

Thanks again