# -*- coding: cp936 -*-
print "Welcom to the X-Printer.\n请输入正确格式,如:\n输入:1,2,6,009-011,14,15,18-21\n结果:1,2,6,9,10,11,14,15,18,19,20,21\n"
while True:
pages = raw_input("请输入需要打印页码:")
##########################################################################判断格式
if pages.isdigit():
if int(pages) == 0 :#输入0,00,000等
page_format = 0
print "格式错误,请重新输入!"
else: print int(pages)
else:
group = pages.split(',')#非0页码进行分组
page_format = 0
for i in range(len(group)):#判断格式是否正确
#情况一:纯数字
if group[i].isdigit():
if int(group[i]) == 0:#分组含0页码
page_format = 0
break
if int(group[i]) != 0:#分组为非0页码
page_format = 1
#情况二:非纯数字
else:
page_format = 0
if '-' in group[i] and group[i].count('-') == 1:#第1步:判断有且仅有1个‘-’
if group[i].index('-') != 0 and group[i].index('-') != len(group[i])-1:#第2步:判断‘-’位于每个分组中间
segment = group[i].split('-')#第3步:分片
if segment[0].isdigit() and segment[1].isdigit():#第4步:判断num1&num2是否合法
former = int((segment[0]))
latter = int((segment[1]))
if former != 0 and latter != 0 and former < latter:
page_format = 1
else:break
else:break
else:break
if page_format == 0:break
############################################################################输出页码
if page_format == 0: print "格式错误,请重新输入!"
if page_format == 1: #输出合法页码
for k in range(len(group)):
#纯数字的打印
if group[k].isdigit():
print int(group[k])
#含Num1-Num2的打印
elif '-' in group[k]:
segment_right = group[k].split('-')
former_right = int(segment_right[0])
latter_right = int(segment_right[1])
for n in range(former_right, latter_right+1):
print n
print '\n'
print "Welcom to the X-Printer.\n请输入正确格式,如:\n输入:1,2,6,009-011,14,15,18-21\n结果:1,2,6,9,10,11,14,15,18,19,20,21\n"
while True:
pages = raw_input("请输入需要打印页码:")
##########################################################################判断格式
if pages.isdigit():
if int(pages) == 0 :#输入0,00,000等
page_format = 0
print "格式错误,请重新输入!"
else: print int(pages)
else:
group = pages.split(',')#非0页码进行分组
page_format = 0
for i in range(len(group)):#判断格式是否正确
#情况一:纯数字
if group[i].isdigit():
if int(group[i]) == 0:#分组含0页码
page_format = 0
break
if int(group[i]) != 0:#分组为非0页码
page_format = 1
#情况二:非纯数字
else:
page_format = 0
if '-' in group[i] and group[i].count('-') == 1:#第1步:判断有且仅有1个‘-’
if group[i].index('-') != 0 and group[i].index('-') != len(group[i])-1:#第2步:判断‘-’位于每个分组中间
segment = group[i].split('-')#第3步:分片
if segment[0].isdigit() and segment[1].isdigit():#第4步:判断num1&num2是否合法
former = int((segment[0]))
latter = int((segment[1]))
if former != 0 and latter != 0 and former < latter:
page_format = 1
else:break
else:break
else:break
if page_format == 0:break
############################################################################输出页码
if page_format == 0: print "格式错误,请重新输入!"
if page_format == 1: #输出合法页码
for k in range(len(group)):
#纯数字的打印
if group[k].isdigit():
print int(group[k])
#含Num1-Num2的打印
elif '-' in group[k]:
segment_right = group[k].split('-')
former_right = int(segment_right[0])
latter_right = int(segment_right[1])
for n in range(former_right, latter_right+1):
print n
print '\n'