Oct-18-2021, 04:13 PM
Hello,
Is there anybody who can help with a problem with the while loops?
__________________________________________________________________
I'm trying to code the following task: creation of a booking system which has to exclude 3 banned names (John, Tom, Jane).
The steps that I had to do are the following:
1- Define the list of banned users: "John", "Tom", "Jane".
2- Create an empty list of members of the guests party.
3- Using an infinitely running while loop and if statements, process the following user inputs:
3a- “Done” - Program should print “Your final group of guests is: {list of guests}” and then exit the infinite loop.
3b- "Any other input (names)" - Program should check whether the guests name is in the banned list.
3b1- If the guest is not in the banned list, the program should add this guest to the list of guests in the party and then print "{name} is allowed in, welcome! Full list of guests is now: {list of guests}".
3b2- If the guest is on the banned list, the program should not add them to the list of guests in the party and should print "{name} is banned! They cannot come in!".
_____________________________________________________________
Example 1
Input:
- John
- Mary
- Bill
- Tom
- Simon
- Done
Desired output:
- John is banned! They cannot come in!
- Mary is allowed in, welcome! Full list of guests is now: [‘Mary’]
- Bill is allowed in, welcome! Full list of guests is now: ['Mary’, ‘Bill’]
- Tom is banned! They cannot come in!
- Simon is allowed in, welcome! Full list of guests is now: [Mary’, 'Bill’, ‘Simon’]
- Your final group of guests is: ['Mary’, 'Bill’, ‘Simon’]
_____________________________________________________________
Example 2:
Input:
- John
- John
- John
- Done
Desired output:
- John is banned! They cannot come in!
- John is banned! They cannot come in!
- John is banned! They cannot come in!
- Your final group of guests is: []
_____________________________________________________________
So far I did the following, but if a banned name is added more than one time, the loop for excluding the name stops after the first iteration and it messes up the allowed users.
Does anybody have a solution for this?
Thanks!!
Is there anybody who can help with a problem with the while loops?
__________________________________________________________________
I'm trying to code the following task: creation of a booking system which has to exclude 3 banned names (John, Tom, Jane).
The steps that I had to do are the following:
1- Define the list of banned users: "John", "Tom", "Jane".
2- Create an empty list of members of the guests party.
3- Using an infinitely running while loop and if statements, process the following user inputs:
3a- “Done” - Program should print “Your final group of guests is: {list of guests}” and then exit the infinite loop.
3b- "Any other input (names)" - Program should check whether the guests name is in the banned list.
3b1- If the guest is not in the banned list, the program should add this guest to the list of guests in the party and then print "{name} is allowed in, welcome! Full list of guests is now: {list of guests}".
3b2- If the guest is on the banned list, the program should not add them to the list of guests in the party and should print "{name} is banned! They cannot come in!".
_____________________________________________________________
Example 1
Input:
- John
- Mary
- Bill
- Tom
- Simon
- Done
Desired output:
- John is banned! They cannot come in!
- Mary is allowed in, welcome! Full list of guests is now: [‘Mary’]
- Bill is allowed in, welcome! Full list of guests is now: ['Mary’, ‘Bill’]
- Tom is banned! They cannot come in!
- Simon is allowed in, welcome! Full list of guests is now: [Mary’, 'Bill’, ‘Simon’]
- Your final group of guests is: ['Mary’, 'Bill’, ‘Simon’]
_____________________________________________________________
Example 2:
Input:
- John
- John
- John
- Done
Desired output:
- John is banned! They cannot come in!
- John is banned! They cannot come in!
- John is banned! They cannot come in!
- Your final group of guests is: []
_____________________________________________________________
So far I did the following, but if a banned name is added more than one time, the loop for excluding the name stops after the first iteration and it messes up the allowed users.
# 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(f'\nGuests requiring to enter: {users}') print( ) # Screening of all users and identification of banned users banned_users = ['John', 'Tom', 'Jane'] for name in banned_users: if name in users: print(f'{name} you are banned! you cannot come in!') users.remove(name) continue else: print(f'{users} you are allowed in, welcome! Full list of guests is now:') print( ) print(f'\n- Your final group of guests is:{users}')_____________________________________________________________
Does anybody have a solution for this?
Thanks!!