标签: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