0

Why is there a syntax error in this code on line 5?

n=int(input("Enter n:"))
if 1<x and 5>=x:
    if n%2==0:
        print("Wierd")
        else:
            print("Not Wierd")
            elif 5<n and 20=<n:
                if n%2==0:
                    print("Not Wierd")
                    else:
                        print("Wierd")
                        elif n>20:
                            if n%2==0:
                                print("Wierd")
                                else:
                                    print("Not Wierd")
1
  • 1
    Sometimes running a code checker like pep8online.com can help run down they syntax errors. Commented Aug 22, 2018 at 12:27

2 Answers 2

2

The else and elif should not be indented that much. They should be on the same indentation-level of the if they match:

n=int(input("Enter n:"))
if 1<x and 5>=x:
    if n%2==0:
        print("Wierd")
    else:
        print("Not Wierd")
elif 5<n and 20=<n:
    if n%2==0:
        print("Not Wierd")
    else:
        print("Wierd")
elif n>20:
    if n%2==0:
        print("Wierd")
    else:
        print("Not Wierd")
Sign up to request clarification or add additional context in comments.

Comments

0

On the line no. 5 you have extra indented else. there is another issue on line 7 elif must have if before and it can't be written after else

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.