Should i make two conditions in el/elif


Console shows
File "python", line 7
elif s = in(yes , no):
SyntaxError: invalid syntax


Oops, try again. Your code looks a bit off. Feel free to peek back at earlier exercises if you need a refresher! Your code threw the following error: invalid syntax (python, line 7)

def shut_down(s):
    return s
    if s == yes:
       return "Shutting down"
    elif s == no:
       return "Shutdown aborted"
    elif s = in(yes , no):
       return sorry


You have an extra elif statement. Change the last elif to an else statement, that returns sorry. Make sure sorry is in quotes like your other two messages.


i have changed elif to else and used quotes for return sorry to ..

still dont gettiing output..


def shut_down(s):
    if s == "yes":
        return "Shutting down"
    elif s == "no":
        return "Shutdown aborted"
        return "Sorry"

You have an extra return statement at the top... return s doesn't belong. The code I just provided should fix your problem, but make sure you understand why. If you need clarification, ask.


clearly understood.

But i have another doubt.. can i use two or more conditions in a if or elif or else statment


You can use two or more conditions in an if or elif statement. This would be accomplished with and or or in between each condition. However, else statements are only run if NONE OF THE OTHERS ARE SATISIFIED, meaning it can't have ANY conditions.


Please give me a example for if and elif for more than two conditions . It will be really helpful.



z = 3

if(w==0 and x==1):
   print("w = 0 and x = 1")
elif(y==3 or z==3):
   print("Either y = 3 or z = 3.")


Thanks a lot i under stood now.

Actually im from Electrical and electronics department.. i have a interview.. probably next week monday or tuesday... so is this website enough for basics?


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.