lundi 3 février 2020

Python If Else Statement: Expected an indented block error [closed]

I would like to start off by saying I am completely new to Python and decided to learn it via HackerRank to improve my CV. I am trying to write a code that reads integer n and outputs a message depending on whether n is an odd or even number and which range it is in. The situations are;

1- If n is odd, print Weird.

2- If n is even and in the inclusive range of 2 to 5, print Not Weird.

3- If n is even and in the inclusive range of 6 to 20, print Weird.

4- If n is even and greater than 20, print Not Weird.

Using trial and error, I got this code;

print('Enter integer n')

n = input()

if (n % 2) and (2<=n<=5):

print('Not Weird')

elif (n % 2) and (6 <= n <= 20):

print('Weird')

elif (n % 2) and (n>20):

print('Not Weird')

else:

print('Weird')

I tried changing the spacing and position of the statements but it gave the same 'Expected an indented block' error. I can't figure out why it keeps giving me this error. Any help is appreciated, thank you.

Aucun commentaire:

Enregistrer un commentaire