-2

I'm a very beginner to python, I dont know what is this error, help

I'm trying this

my example

i = 10
if i % 2 == 0:
print("Number is even")
else:
print("Number is odd")

screenshot

tdelaney
  • 73,364
  • 6
  • 83
  • 116
Hutch
  • 167
  • 2
  • 8

1 Answers1

3

Python expects indentations underneath if statements and else statements. This should work.

i = 10
if i % 2 == 0:
    print("Number is even")
else:
    print("Number is odd")

For further clarification, essentially any Python statement that ends in a : is generally gonna be followed by an indented code block. The indented code block includes all the statements that you want Python to execute.

In this case, if and else both have the same level of indentation and each of them has a statement that follows that needs to be indented.

E. Ducateme
  • 4,028
  • 2
  • 20
  • 30
  • 1
    It's sufficient to say statements; one type of statement is the expression statement, which consists of a single expression. – chepner Feb 23 '20 at 23:13