码迷,mamicode.com
首页 > 编程语言 > 详细

用户排序

时间:2017-04-01 22:11:24      阅读:224      评论:0      收藏:0      [点我收藏+]

标签:release   python   number   error   count   



#给输入的用户按照首字母排序#




#!/usr/bin/env python
#coding:utf-8

‘‘‘
Program:
    Sort and output by name
History:
2017.03.29      Mr.liu      First release
‘‘‘

‘‘‘
total = input("the total number of name:")
li = []
errcount = 0
count = 0
while count < total:
    name = raw_input("Please input %d name(s): \n" % (4 - count))
    if "," in name:
        li.append(name)
        count += 1
    else:
        errcount += 1
        print "ERROR:%d time(s) bad input:‘,‘ \n Please try agin." %(errcount)
li = sorted(li)
dic = {}.fromkeys(li)
print "The sorted list by first name is:"
for d in dic.keys():
    print d
‘‘‘


count = input("Enter total munber of name:")
li = []
errCount = 0
i = 0
while i < count:
    name = raw_input("Please input your name:")
    if "," in name and "," != name[0] and name.index(",") != len(name) - 1 and name.count(",") == 1:
        li.append(name)
        i += 1
    else:
        errCount += 1
        print "ERROR:%d time(s) bad input:‘,‘ Please try agin." %(errCount)
else:
    li = sorted(li)

print "The sorted list by first name is:"
for i in li:
    print i


本文出自 “12449513” 博客,请务必保留此出处http://12459513.blog.51cto.com/12449513/1912420

用户排序

标签:release   python   number   error   count   

原文地址:http://12459513.blog.51cto.com/12449513/1912420

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!