0

I'm confused as to why the if statements highlighted aren't working. If I type "remove" or "removeall", the message I have for each message does not print.

https://pastebin.com/iawK1gyT

while user != "":
    if user.lower() != "remove" or user.lower() != "removeall":
        recipients.append(user)
        userQuery()

    elif user.lower() == "remove":
        if not recipients:
            print("You haven't added any recipients yet.")
            userQuery()

        else:
            del recipients[-1] # Removes the last item of the list

    elif user.lower() == "removeall":
        if recipients:
            print("Removed every user from the recipient list.")
            recipients = [] # Removes every item from the list
            userQuery() 

        else:
            print("Can't delete an empty recipients list.")
            userQuery()
martineau
  • 119,623
  • 25
  • 170
  • 301
  • 6
    `user.lower() != "remove" or user.lower() != "removeall"` is always `True`, because `user` is either not `remove` or it is not `removeall`. You likely want `if user.lower() != "remove"` **and** `user.lower() != "removeall":` – AJNeufeld May 29 '18 at 21:52
  • 3
    More idiomatically, you can use `user.lower() not in ('remove', 'removeall')`. – jpp May 29 '18 at 21:55
  • Or, reorder your tests. `if user.lower() == "remove":` followed by your remove code, and then `elif user.lower() == "removeall":` followed by your remove-all code, and then `else:` followed by your append user code. – AJNeufeld May 29 '18 at 22:01

0 Answers0