开发者

Python Help finding value of i

开发者 https://www.devze.com 2023-02-12 09:49 出处:网络
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):

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

精彩评论

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