Python module returning True
<p>I'm writing Python for a kind of computer, and the login module always returns true, even if it's not in the <code>users</code> dictionary:</p>

<pre><code>cur_user = "null"
users = {
    "Splavacado100": "20310"
}

def login():
    good_login = 0
    user_name = raw_input("Enter your username: ")
    for user in users:
        if user == user_name:
            good_login = 1
    if good_login == 1:
        user_password = raw_input("Enter your password: ")
        if users[user_name] == user_password:
            return True
        else:
            return False
    else:
        return "None"

def OS():
    log_att = False
    log_att = login()
    if log_att:
        print "True"
    else:
        print "False"

OS()
</code></pre>

<p>How can I make it return false in those cases?</p>

<p>I am using Python 2.7.10.</p>

<p>I think your login function should look more like;</p>

<pre><code>def login():
    raw_user = raw_input("Enter your username: ")
    password = users.get(raw_user)
    if not password:
        return False
    raw_password = raw_input("Enter your password: ")
    if password == raw_password:
        return True
    return False
</code></pre>

<p>Then your second function can be simplified:</p>

<pre><code>def OS():
    if login():
        print "True"
    else:
        print "False"
</code></pre>

python python-2.7