What's going on with my if-else statement? (Python 3.3)

前端 未结 4 588
终归单人心
终归单人心 2020-12-22 05:35

I\'m writing conditional statements for a billing program project. It\'s a bit advanced for a beginner I know but I welcome the challenge. Anyways, I plan on starting the pr

4条回答
  •  无人及你
    2020-12-22 06:34

    You need to compare your name with all names. Problem lies here:

    if username == "cking" or "doneal" or "mcook":
    

    Python evaluates first one to either true or false and then doing or with something, that evaluates to True in this context and at the end your comparison looks like this:

    if username == "cking" or True or True:
    

    which ends up being True. As suggested, you should use:

    if username == "cking" or username == "doneal":
    

    or simply do:

    if username in ("cking", "doneal"):
    

    The same applies to password.

提交回复
热议问题