【问题标题】:Python Help finding value of iPython 帮助查找 i 的值
【发布时间】:2011-02-20 21:13:44
【问题描述】:

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

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

【问题讨论】:

  • 你为什么不试试那个代码并调用那个函数呢?

标签: python python-2.6


【解决方案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

【讨论】:

  • 非常感谢,我很感激。我只是在 python 中做了它,它吐出了 5。
  • def sumlist(inputlist): listsum =0 for item in inputlist: listsum = listsum + item return listsum # 您对问题的描述(在评论中)
  • 如果这个答案解决了你的问题,你应该把它标记为正确答案:P
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-03-14
  • 2011-09-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多