#πŸ”’ PYTHON IF STATEMENT BROKEN???

36 messages Β· Page 1 of 1 (latest)

silver silo
#

I'm trying to make this code print(True) if the username and password given matches the admin list.

# Admin list format = ["name1", "password1", "name2", "password2"...]
admin = ["CalvinSup", "LynnGoated", "DavidLynn", "CalvinBestStudent"]

isAdmin = False

username = "CalvinSup"
password = "LynnGoated"

for i in range(0, len(admin), 2):

    print(i)
    print(i+1)
    print(admin[i])
    print(admin[i+1])
    if (username == admin[i]) and (password == admin[i+1]):
        isAdmin == True

if isAdmin:
    print(True)

elif not isAdmin:
    print(False)

But it didn't work cuz here's the output, I even added print(i), print(i+1), etc... to check the values

Here's the full output:

0
1
CalvinSup
LynnGoated
2
3
DavidLynn
CalvinBestStudent
False

As you can see it didn't work cuz it returned False, is there some logical error?

soft gazelleBOT
#

@silver silo

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

shut blaze
#

definitely a logic error

#

that elif is confusing

silver silo
shut blaze
#

why not just else

silver silo
shut blaze
#
if isAdmin:
  print("Admin is in")
else:
  print("Admin is not in")
#

ok

silver silo
#

its' still false

shut blaze
#

Is the password just another admin's username?

silver silo
#

the problem is that the first if loop didn't execute

silver silo
shut blaze
#

Strange way to arrange it

#

Why not dict?

silver silo
#

cuz idk how to use a dict

silver silo
shut blaze
silver silo
shut blaze
#

line 16

marsh sphinx
silver silo
#

oh hell nah

#

I'm really sorry @marsh sphinx and @shut blaze

#

for bothering u

#

I'm sorry

shut blaze
#

its fine

silver silo
#

I made a silly mistake

marsh sphinx
#

chill

silver silo
#

but thank u man

shut blaze
#

it happens to all of us

silver silo
#

thank u sir

#

!close

soft gazelleBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.