输入名字,判断姓名是否合法。三次输入错误后直接跳出。
如果输入正确,则排序后输出
#!/usr/bin/env python
#coding:utf-8
num = 1
errcount = 0
count = input("Enter total number of names:")
namelist = []
while num <= count:
print "please enter name %d:" %num
name = raw_input()
if "," in name and name.index(",") != 0 and name.index(",") != len(name) - 1:
namelist.append(name)
num +=1
else:
print "wrong format...should be Last,First."
errcount +=1
print "Enter %d error number of names " %errcount
print sorted(namelist)
时间: 2024-10-09 03:35:48