user2720912
user2720912

Reputation: 41

Using IF after Else in python

I am a beginner in python programming. I have a small doubt that while performing some conditional expression using "if-elif-else" block, if i am using "if" after "else" would the code under "if" run or not. I know its a bad practice, but i have to integrate a pre-written code with my application. for example:

jk=10

if(jk>5):
    print("hello")

elif(jk<20):
    print("not")

else:
    print("gone")

if(jk==10):
    print("home")

When i type the above snippet in interpreter it gives me the below error:

... if(jk==10):

File "<stdin>", line 5

    if(jk==10):

SyntaxError: invalid syntax

However when i write this in a script and run it through command line it runs perfectly without any error. Can somebody point out what i am missing here.

Upvotes: 2

Views: 3268

Answers (1)

inspectorG4dget
inspectorG4dget

Reputation: 113955

The ... says that you are still within the code block for the else and python doesn't expect the dedent for the next if. Try hitting ENTER one more time for the ... to turn back into a >>> and your code will work!

Upvotes: 8

Related Questions