Python帮助查找i的值

时间:2011-02-20 21:13:44

标签: python python-2.6

当a为6时,循环体末端的i值是多少?

def loopIdentification():
    i=0
    for a in range(2,8):
        i=i+a-3
    return i

1 个答案:

答案 0 :(得分:1)

<强> 5

>>> def loopIdentification():
    i=0
    for a in range(2,8):
        i=i+a-3
        print a, i
    return i

>>> loopIdentification()
2 -1
3 -1
4 0
5 2
6 5
7 9
9