【发布时间】:2018-05-11 23:49:06
【问题描述】:
我需要帮助生成这样的输出:
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
我已经努力创建一个可以执行此操作的程序,但无济于事。我将在代码本身的问题中发表评论。提前感谢您的帮助。
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()
【问题讨论】:
标签: python python-3.x list sorting input