Oct-20-2021, 02:14 PM
Hi all, thanks for the inputs. I followed your suggestions and I thought that the coding was working, but I found another problem (hopefully the last). Accordingly to the last revision (below) the code looks working well except for one thing: the list of the accepted_users repeats itself as many times as the number of accepted_users. Practically if (out of the banned_users) I put e.g. other 3 names, I'll get the list of the accepted_users with the 3 names repeated 3 times (if 4 names, 4 times and so on). Does anybody have a clue on this problem?
# Creation of an empty list of all users and ask to all of them the name until done users = [] user = '' while user != 'Done': user = input("Please write your name here: ").title().strip() if user != 'Done': users.append(user) print( ) # Screening of all users and identification of banned users banned_users = ['John', 'Tom', 'Jane'] accepted_users = [] for name in users: if name in banned_users: banned_users.append(name) print(f'{name} is banned! They cannot come in!') banned_users.remove(name) else: for name in users: if name not in (banned_users): accepted_users.append(name) print(f'{name} is allowed in, welcome! Full list of guests is now: {accepted_users}') print( ) # List of final group of accepted guests print(f'\nYour final group of guests is: {accepted_users}')