Should i make two conditions in el/elif


#1



https://www.codecademy.com/en/courses/python-beginner-c7VZg/4/1?curriculum_id=4f89dab3d788890003000096


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

And

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


#2

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.


#3

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

still dont gettiing output..


#4

def shut_down(s):
    if s == "yes":
        return "Shutting down"
    elif s == "no":
        return "Shutdown aborted"
    else:
        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.


#5

clearly understood.

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


#6

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.


#7

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


#8

Sure...

w=0
x=1
y=2
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.")

#9

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?


#10

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