Iteration for Factorials
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. -- http://mail.python.org/mailman/listinfo/python-list
Re: Iteration for Factorials
On 22 Oct, 13:28, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> 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
Here 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)
--
http://mail.python.org/mailman/listinfo/python-list
Re: Iteration for Factorials
On 22 Oct, 13:43, Marco Mariani <[EMAIL PROTECTED]> wrote:
> Py-Fun wrote:
> > def itforfact(n):
> > while n<100:
> > print n
> > n+1
> > n = input("Please enter a number below 100")
>
> You function should probably return something. After that, you can see
> what happens with the result you get.
Marco, Thanks for the tip. This now works:
def itforfact(n):
while n<100:
print n
n = n+1
n = input("Please enter a number below 100")
itforfact(n)
Is it a "factorial" though?
--
http://mail.python.org/mailman/listinfo/python-list
