I need help producing an output like this:
1. Enter a member: samantha
Names: ['Samantha']
2. Enter a member: susan
Names: ['Samantha', 'Susan']
3. Enter a member: billy
Names: ['Billy', 'Samantha', 'Susan']
4. Enter a member: billy
4. Enter a member: samantha
4. Enter a member: Jason
Names: ['Billy', 'Jason', 'Samantha', 'Susan']
5. Enter a member:
Members:
1. Billy
2. Jason
3. Samantha
4. Susan
I've made an effort to create a program which does this, but to no avail. I will be commenting in my questions in the code itself. Thanks in advance for the help.
def function():
x = []
#a = "1." # I tried to number the questions by adding these but it doesnt work
while True:
#a += 1
name = input("Enter name: ").title()
x.append(name)
print("Names:", x)
#if name == name: # this condition is made so that an input that is typed in again doesn't get included in the list
#name = input("Enter name: ").title()
# where should I add an insert() here to have the list alphabetically ordered?
if not name: # pressing enter prints out the second half of the output, listing the members
#print("\nMembers:", x).sort()
break
function()