-1

I am very new in python. Could you help?

x = 1 
y = 0


if x > y: 
   if x < 0:
         print (" X é maior que Y e menor que 0.")
    else:
         print (" X é maior que Y e maior que 0.")

if x < y:
      if x < 0:
            print ("X é menor que Y e menor que 0.")
       else:
            print ("X é menor que Y e maior que 0.")

line 16 else: ^ IndentationError: unindent does not match any outer indentation level [Finished in 0.1s]

That is the error? Why?

Thank for your help, Ricardo Rocha

  • 1
    In both cases you can see with the naked eye that it is not indented to the same level as the preceding `if` – roganjosh Dec 18 '18 at 20:35
  • Your `else` statements are not indented in the same way as your `if` statements. If you squint you can see it. – Makoto Dec 18 '18 at 20:35
  • `if` and `else` need to have *exactly* the same indentation level. – Klaus D. Dec 18 '18 at 20:35
  • Your `if` and `else` need to be vertically aligned ... the `else` is out by one character – donkopotamus Dec 18 '18 at 20:36
  • Possible duplicate of [IndentationError: unindent does not match any outer indentation level](https://stackoverflow.com/questions/492387/indentationerror-unindent-does-not-match-any-outer-indentation-level) – emsimpson92 Dec 18 '18 at 20:38

1 Answers1

2

Your indentations are wrong. Python uses whitespace as part of the code formatting. if and else need to have the same indentation level.

x = 1 
y = 0


if x > y: 
    if x < 0:
        print (" X é maior que Y e menor que 0.")
    else:
        print (" X é maior que Y e maior que 0.")

if x < y:
    if x < 0:
        print ("X é menor que Y e menor que 0.")
    else:
        print ("X é menor que Y e maior que 0.")
Tim
  • 2,756
  • 1
  • 15
  • 31
  • 2
    This is a typo, man. Should be closed as such. – Makoto Dec 18 '18 at 20:35
  • 3
    I agree, but I'm not sure why this answer was downvoted. Typo or not, he's right. – emsimpson92 Dec 18 '18 at 20:37
  • 1
    @emsimpson92: That's neither here nor there. The question should be closed instead of answered, since it's not going to be of lasting value to anyone looking for this answer (since there's ***already*** a wealth of information about this in Python). – Makoto Dec 18 '18 at 20:38
  • 2
    I didn't upvote or downvote the answer either way. I just flagged it as a duplicate, but if someone wants to answer a duplicate I guess I just don't see an issue with that. – emsimpson92 Dec 18 '18 at 20:41