因子的迭代 [英] Iteration for Factorials
问题描述
我试图编写一个函数,使用迭代而不是递归生成一个
数的阶乘。任何简单的想法都会受到赞赏。
Py-Fun写道:
< blockquote class =post_quotes>
我试图编写一个函数,使用迭代而不是递归来生成一个
数的阶乘。任何简单的想法都会受到赞赏。
向我们展示您的尝试,我们可能会建议修复。因为否则这个
听起来像是家庭作业。
Diez
10月22日,13: 28,Diez B. Roggisch, < de ... @nospam.web.dewrote:
Py-Fun写道:
我试图编写一个函数,使用迭代而不是递归生成一个
数的阶乘。任何简单的想法都会受到赞赏。
向我们展示您的尝试,我们可能会建议修复。因为否则这个
听起来像是家庭作业。
Diez
这是我徒劳的尝试。小心这一点,我只是跑了
类似的东西,它永远不会结束......
def itforfact(n):
而n< 100:
打印n
n + 1
n =输入(请输入低于100的数字)
itforfact(n)
Py-Fun写道:
我试图编写一个函数,使用迭代而不是递归来生成一个
数的阶乘。任何简单的想法都会受到赞赏。
与什么相比,一个复杂的?
I''m stuck trying to write a function that generates a factorial of a
number using iteration and not recursion. Any simple ideas would be
appreciated.
Py-Fun wrote:
I''m stuck trying to write a function that generates a factorial of a
number using iteration and not recursion. Any simple ideas would be
appreciated.Show us your attempts, and we might suggest a fix. Because otherwise this
sounds suspiciously like homework.
Diez
On 22 Oct, 13:28, "Diez B. Roggisch" <de...@nospam.web.dewrote:Py-Fun wrote:I''m stuck trying to write a function that generates a factorial of a
number using iteration and not recursion. Any simple ideas would be
appreciated.
Show us your attempts, and we might suggest a fix. Because otherwise this
sounds suspiciously like homework.
DiezHere is my futile attempt. Be careful with this though, I just ran
something similar and it was never ending...
def itforfact(n):
while n<100:
print n
n+1
n = input("Please enter a number below 100")
itforfact(n)
Py-Fun wrote:
I''m stuck trying to write a function that generates a factorial of a
number using iteration and not recursion. Any simple ideas would be
appreciated.As opposed to what, a complicated one?
这篇关于因子的迭代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!