Python Forum
while loops - 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: while loops (/thread-35300.html)

Pages: 1 2


RE: while loops - Paulman - Oct-20-2021

OK, I think I found the bug, below the final revision:

# 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)
        continue
    else:
        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}')



RE: while loops - deanhystad - Oct-20-2021

You are still doing it wrong. THERE SHOULD ONLY BE ONE LOOP!!! You should be checking if the name is banned immediately after the name is entered (3b). Only add the name to the list if it is not banned (3b1).