首页 > 代码库 > 输入姓名脚本

输入姓名脚本


输入名字,判断姓名是否合法。三次输入错误后直接跳出。

如果输入正确,则排序后输出


#!/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)

本文出自 “12444546” 博客,谢绝转载!

输入姓名脚本