#! /usr/bin/python
i = 0
o = 7
p = 2
numbers = []
def w(startnum,endnum):
while startnum < endnum:
print "At the top is %d" % startnum
numbers.append(startnum)
startnum += p #使用变量p
print "Numbers now: ",numbers
print "At the bottom i is %d" % startnum
w(i,o) #函数w引用实参i,o
print "The numbers: "
for num in numbers:
print num
'''-----------------------将代码改为用for-loop----------------'''
#! /usr/bin/python
i = 0
o = 6
numbers = []
for s in range(i,o):
print "print i: %d " % s
numbers.append(s)
print "Numbers now: ", numbers
print "The numbers: "
for num in numbers:
print num
'''----------range()在for-loop中的用法-----------'''
i = 1
o = 6
numbers = range(i,o)
for j in numbers:
print "numbers was: %d" % j
阅读(722) | 评论(0) | 转发(0) |