为步长, 从 f 计数到 t , 包括 f 和 t . 例如, 如果输入的是 f == 2, t == 26, i == 4 , 程序
将输出 2, 6, 10, 14, 18, 22, 26.
f1, t1, i1 = raw_input('pls input three num:').split()
f = int(f1)
t = int(t1)
i = int(i1)
a = max(f, t)
b = min(f, t)
c = (a-b)/i
if (a-b)/i ==0:
for n in range(0, c+1):
m = b + n*i
n = n+1
print 'The num list is %d'%(m)
else:
for n in range(0, c+1):
m = b + n*i
n = n+1
print 'The num list is %d'%(m)
print 'The num list is %d'%(a)
很麻烦对不对??有个更简单的:
f1, t1, i1 = raw_input('pls input three num:').split()
f = int(f1)
t = int(t1)
i = int(i1)
a = max(f, t)
b = min(f, t)
for n in range (b, a, i):
print 'The num lis is %d'%(n)
print 'The num lis is %d'%(a)
巧妙使用range(start, end, step)方法