编写一个程序,让用户输入3个数字:(f)rom,(t)o和(i)ncrement。以i为步长,从f计数到t,包括f和t。例如,如果输入的是f = 2,t = 26,i = 4,程序将输出2,6,10,14,18,22,26。
#!/usr/bin/env python
#coding=utf-8
for i in range(2,30,4):
print i,
f=int(raw_input("please input From:"))
t=int(raw_input("please input To:"))
i=int(raw_input("plese input I:"))
for num in range(f,t ,i):
print num,
执行:
[root@test1 Flying]# python for.py
2 6 10 14 18 22 26 please input From:2
please input To:40
plese input I:4
2 6 10 14 18 22 26 30 34 38