开发者

Python Help finding value of i

What is the value of i at the end of the loop body when a is 6?

def loopIdentification():
    i=0
    for a in range(2,8):
开发者_如何转开发        i=i+a-3
    return i


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜