jeudi 17 décembre 2020

I don't know which is my error. I am doing a homework, I tried with the following function, but I my grade was 0 [closed]

def update(bank, log_in, username, amount):

'''In this function, you will try to update the given user's bank account with the given amount.
The amount is an integer, and can either be positive or negative.

To update the user's account with the amount, the following requirements must be met:
- The user exists in log_in and his/her status is True, meaning, the user is logged in.

If the user doesn't exist in the bank, create the user.
- The given amount can not result in a negative balance in the bank account.

return True if the user's account was updated.

For example:
- Calling update(bank, log_in, "Brandon", 100) will return False, unless "Brandon" is first logged in.  Then it
will return True.
- Calling update(bank, log_in, "Brandon", -200) will return False
'''

def update(bank, log_in, username, amount): if username in log_in.keys(): if log_in[username]==False: return False elif log_in[username]==True: if amount>0: bank[username]=bank[username]+amount return True if username not in log_in.keys(): log_in[username] = False return False else: return False

Aucun commentaire:

Enregistrer un commentaire