0

So I have tried searching this but apparently nobody ever needed to do this simple thing before?

I want to a variable to have multiple strings. so basically it is:

command = input()
commands = "start" or "stop" or "help"

 while command.lower() == commands:
    dosomething()
 else
    dosomething()

This is basically the idea, but it only take the first string which is "start" but ignores the other 2. I understand that it reads it as ( commands = "start" ) so I tried making it commands = "start" or commands = "stop" or commands = "help" but it flat out says it is wrong. so what did I do instead? Can someone help? Thanks

CyberWTF
  • 11
  • 2
  • Normally you'd put all the (accepted) values in a list and use the `in` operator to check if the input it's one of them. Also, you could also throw a `.strip()` in there to ease things a little. – Lohmar ASHAR Dec 13 '21 at 19:59
  • I can assure you millions of people have already tried to this – azro Dec 13 '21 at 19:59
  • 1
    Does this answer your question? [How to test multiple variables against a single value?](https://stackoverflow.com/questions/15112125/how-to-test-multiple-variables-against-a-single-value) – Brian61354270 Dec 13 '21 at 20:00
  • You can only assign a *single* object to a variable. That object can be a *container*, though, like a `list`, `dict` or `tuple` – juanpa.arrivillaga Dec 13 '21 at 20:04

1 Answers1

1

What you need is a list, then check for inclusion with if (not while which is a loop)

command = input(">>")
commands = ["start", "stop", "help"]

if command.lower() in commands:
    print("start/stop/help")
else:
    print("other")
azro
  • 53,056
  • 7
  • 34
  • 70