正在加载图片...
Summation Example Function of a single argument def cube(k): (not called "term") return pow(k,3) A formal parameter that will def summation(n,term) be bound to a function """Sum the first n terms of a sequence. >>summation(5,fcube) 225) n鞋 The cube function is passed 0+1+8+27+64+125 total,k =0,1 as an argument value while k <n: total,k total +'term(k),k 1 return total The function bound to term gets called hereSummation Example def cube(k): return pow(k, 3) def summation(n, term): """Sum the first n terms of a sequence. >>> summation(5, cube) 225 """ total, k = 0, 1 while k <= n: total, k = total + term(k), k + 1 return total Function of a single argument (not called "term") A formal parameter that will be bound to a function The cube function is passed 0 + 1 + 8 + 27 + 64 + 125 as an argument value The function bound to term gets called here
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有