Python Forum
homework - banking system - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: homework - banking system (/thread-23683.html)



homework - banking system - Massimo16 - Jan-12-2020

i need to search customers by their last name in order to allow the admin user to have access to the customers account.
i have already created the admin search but can sombody tell me why the search_customers_by_name is not working Sad
 def search_admins_by_name(self, admin_username):
        #STEP A.2
        found_admin = None
        for a in self.admins_list:
            username = a.get_username()
            if username == admin_username:
                found_admin = a
                break
        if found_admin == None:
            print("\n The Admin %s does not exist! Try again...\n" %admin_username)
        return found_admin 
        
    def search_customers_by_name(self, customer_lname):
        #STEP A.3
        found_account = None
        for a in self.accounts_list:
            lname = a.get_last_name()
            if lname == customer_lname:
                found_account = a
                break
            if found_account == None:
                print("\n The account does not exist! Try again...\n" %customer_lname)
            return found_account



RE: homework - banking system - ibreeden - Jan-13-2020

What do you mean by "not working"? Do you get an error message or does the method not give a result? Or the wrong result? In the last two cases: examine the accounts_list. Does it contain an element with the last_name you are looking for?


RE: homework - banking system - jefsummers - Jan-13-2020

One obvious issue is that line 21 would be triggered every time through the loop. I think you only want it to say not found if it has looped through every account