Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

why wont my elif statement work

+2 votes
asked Sep 25, 2022 by Amir Matar (140 points)
joing=input("Whats your name: ")
if joing =="Amir" or "Daddy":
     pas=input("Whats your password: ")
elif print("unknown user")

2 Answers

+2 votes
answered Sep 26, 2022 by xDELLx (10,500 points)

elif will need a condition to evaluate, which is missing in ur code.

Use else: if there is no condition.

Also check line #2, using logical OR is not ok .

Corrected code below.


  1 joing=input("Whats your name: ")
  2 if joing =="Amir" or joing=="Daddy":
  3      pas=input("Whats your password: ")
  4 elif joing =="xxx" :
  5     print ("In elif: :)")
  6 else:
  7      print("unknown user")

0 votes
answered Oct 1, 2022 by dsa learner (260 points)
elif need condition to operate

no condition is supplied in your code

You can use else here

or

if joing == "Amir" or "Daddy":

   pas = input("Whats your password:")

print("unknown user")
commented Oct 6, 2022 by Osman (170 points)
your answer is fully wrong. delete it.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...