python 数字判断
25,24,23,02,05,06,6513,14,15,16,66,53,2203,60,04,06,07,09,2321,22,23,02,05,06,081.读取t...
25,24,23,02,05,06,65
13,14,15,16,66,53,22
03,60,04,06,07,09,23
21,22,23,02,05,06,08
1.读取txt 文件内容判断第一个数和最后一个数的尾数是否相等
2.判断是否有3个或3上以上的为连续数
3.输出到另一个txt文件
25,24,23,02,05,06,65 25,65 25,24,23
13,14,15,16,66,53,22 13,14,15,16
03,60,04,06,07,09,23 03,23
21,22,23,02,05,06,08 21,22,23 展开
13,14,15,16,66,53,22
03,60,04,06,07,09,23
21,22,23,02,05,06,08
1.读取txt 文件内容判断第一个数和最后一个数的尾数是否相等
2.判断是否有3个或3上以上的为连续数
3.输出到另一个txt文件
25,24,23,02,05,06,65 25,65 25,24,23
13,14,15,16,66,53,22 13,14,15,16
03,60,04,06,07,09,23 03,23
21,22,23,02,05,06,08 21,22,23 展开
展开全部
#!/usr/bin/env python
# coding: utf-8
#
# author: Tim Wang
# filename: baidu.py
# date: Apr., 2014
context = """25,24,23,02,05,06,65
13,14,15,16,66,53,22
03,60,04,06,07,09,23
21,22,23,02,05,06,08"""
data = [
ln.strip().split(',')
for ln in context.splitlines()
]
def check1(row):
return int(row[0])%10 == int(row[-1])%10
def check2(row):
irow = map(int, row)
for i, n in enumerate(irow):
if irow[i:i+3] in (range(n, n+3), range(n, n-3, -1)):
return irow[i:i+3]
else:
return None
for row in data:
print row, '\t',
print check1(row) and "%2s,%2s"%(row[0], row[-1]) or "_____" ,
sub = check2(row)
if sub:
print '\t', sub
else:
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询