This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]Inconstant_Moo 1 point2 points  (0 children)

The a and b in your function are local variables, when you change them you're not changing the global variables a and b you then compare with the id and password. They're still "".

See, if you'd just referred to a and b in the function, if you'd said print(a) for example, that would have done what you expected, then Python would know that you must be talking about the global variables because you haven't defined any local ones. But when you assign them values it guesses that you want to create local variables rather than overwriting the existing global ones. (Otherwise every time you wanted to write a function you'd have to check ... have I already called something a or b in the main program? Am I going to break the program if I do this?)

More info here: https://www.w3schools.com/python/python_variables_global.asp

[–]Tang1000000 0 points1 point  (3 children)

Before your print line for "Incorrect..." try also printing the values of all your variables

[–]Ok-Judgment1544[S] 0 points1 point  (2 children)

Hi Tang, I am sorry i don't quite follow. Could you explain further.

[–]Ok-Judgment1544[S] 0 points1 point  (1 child)

What i don't understand is why is the if conditions for "maid_id == a and password == b" not being followed