Re: Iteration for Factorials

2007-10-30 Thread Gabriel Genellina
En Tue, 30 Oct 2007 15:37:57 -0300, [EMAIL PROTECTED] <[EMAIL PROTECTED]> escribió: > On Oct 30, 10:25 am, "J. Clifford Dyer" <[EMAIL PROTECTED]> wrote: >> The great part about this recursive solution is that you don't have to >> worry about the stack limit because performance degrades so qui

Re: Iteration for Factorials

2007-10-30 Thread [EMAIL PROTECTED]
On Oct 30, 1:52 pm, "J. Clifford Dyer" <[EMAIL PROTECTED]> wrote: > On Tue, Oct 30, 2007 at 11:37:57AM -0700, [EMAIL PROTECTED] wrote regarding > Re: Iteration for Factorials: > > > > > > > > > On Oct 30, 10:25 am, "J. Clifford Dyer" <

Re: Iteration for Factorials

2007-10-30 Thread J. Clifford Dyer
On Tue, Oct 30, 2007 at 11:37:57AM -0700, [EMAIL PROTECTED] wrote regarding Re: Iteration for Factorials: > > On Oct 30, 10:25 am, "J. Clifford Dyer" <[EMAIL PROTECTED]> wrote: > > On Tue, Oct 30, 2007 at 01:09:38PM +0100, Boris Borcic wrote regarding Re:

Re: Iteration for Factorials

2007-10-30 Thread [EMAIL PROTECTED]
On Oct 30, 10:25 am, "J. Clifford Dyer" <[EMAIL PROTECTED]> wrote: > On Tue, Oct 30, 2007 at 01:09:38PM +0100, Boris Borcic wrote regarding Re: > Iteration for Factorials: > > > > > Py-Fun wrote: > > > I'm stuck trying to write a function

Re: Iteration for Factorials

2007-10-30 Thread J. Clifford Dyer
On Tue, Oct 30, 2007 at 01:09:38PM +0100, Boris Borcic wrote regarding Re: Iteration for Factorials: > > 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 > >

Re: Iteration for Factorials

2007-10-30 Thread J. Clifford Dyer
On Tue, Oct 30, 2007 at 01:09:38PM +0100, Boris Borcic wrote regarding Re: Iteration for Factorials: > > 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 > >

Re: Iteration for Factorials

2007-10-30 Thread auzaar
On Oct 30, 3:30 pm, Nick Craig-Wood <[EMAIL PROTECTED]> wrote: > Anurag <[EMAIL PROTECTED]> wrote: > > What about this no map, reduce, mutiplication or even addition > > Its truly interative and You will need to interate till infinity if > > you want correct answer ;) > > > deffactorial(N): > >

Re: Iteration for Factorials

2007-10-30 Thread Boris Borcic
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. > fact = lambda n : len(map([1].__imul__,range(1,n+1))[0]) hth :) BB -- http://mail.python.org/mailman/listinfo/python-list

Re: Iteration for Factorials

2007-10-30 Thread Marco Mariani
Nick Craig-Wood wrote: > Note you can write your middle loop as > > for i in range(I): > number = myNumer[:] > random.shuffle(number) > if number == myNumer: > count+=1 Nice. Try 'em all, then count 'em. Another wtfery would be a SQLAlchemy solution, gene

Re: Iteration for Factorials

2007-10-30 Thread Nick Craig-Wood
Anurag <[EMAIL PROTECTED]> wrote: > What about this no map, reduce, mutiplication or even addition > Its truly interative and You will need to interate till infinity if > you want correct answer ;) > > def factorial(N): > """ > Increase I ...and go on increasing... > """ >

Re: Iteration for Factorials

2007-10-30 Thread Anurag
What about this no map, reduce, mutiplication or even addition Its truly interative and You will need to interate till infinity if you want correct answer ;) def factorial(N): """ Increase I ...and go on increasing... """ import random myNumer = range(N) count = 0 I =

Re: Iteration for Factorials

2007-10-26 Thread Steven Bethard
Nicko wrote: > If you don't like the rounding errors you could try: > > def fact(n): > d = {"p":1L} > def f(i): d["p"] *= i > map(f, range(1,n+1)) > return d["p"] > > It is left as an exercise to the reader as to why this code will not > work on Py3K Serves yo

Re: Iteration for Factorials

2007-10-26 Thread Nicko
On Oct 25, 2:36 am, Paul Rubin wrote: > Lou Pecora <[EMAIL PROTECTED]> writes: > > There might even be an array method that can be adapted to get the > > product. Is there a product method? (analogous to a sum method) > > The "reduce" function which is being removed from

Re: Iteration for Factorials

2007-10-26 Thread Marco Mariani
[EMAIL PROTECTED] wrote: > class fact_0(object): > value = 1 [... > def __new__(self, n_): > class spanish_inquisition(object): > __metaclass__ = fact_meta > n = n_ > return spanish_inquisition() You wrote lots o

Re: Iteration for Factorials

2007-10-25 Thread Lou Pecora
In article <[EMAIL PROTECTED]>, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > > def factorial(i): > >fact=1.0 > >for n in xrange(i): > > fact=n*fact > >return fact > > Simple minded indeed. > > >>> factorial(3) > 0.0 > Whoops, should have xrange(i)+1 there. Or, better, xr

Re: Iteration for Factorials

2007-10-24 Thread Paul Rubin
[EMAIL PROTECTED] writes: > > It's only a moment before the metaclass and > > the Twisted solution come along. :) > > I couldn't resist. It's not as elegant as I hoped, but hey, at least > it memoizes the intermediate classes :-) It gets even weirder in Haskell. http://www.willamette.edu/~fruehr

Re: Iteration for Factorials

2007-10-24 Thread Paul Rubin
Lou Pecora <[EMAIL PROTECTED]> writes: > There might even be an array method that can be adapted to get the > product. Is there a product method? (analogous to a sum method) The "reduce" function which is being removed from python in 3.0. import operator def factorial(n): return reduce(operat

Re: Iteration for Factorials

2007-10-24 Thread [EMAIL PROTECTED]
On Oct 24, 5:19 pm, [EMAIL PROTECTED] wrote: > Tim Golden napisa (a): > > > It's only a moment before the metaclass and > > the Twisted solution come along. :) > > I couldn't resist. It's not as elegant as I hoped, but hey, at least > it memoizes the intermediate classes :-) > > class fact_0(object

Re: Iteration for Factorials

2007-10-24 Thread marek . rocki
Tim Golden napisa (a): > It's only a moment before the metaclass and > the Twisted solution come along. :) I couldn't resist. It's not as elegant as I hoped, but hey, at least it memoizes the intermediate classes :-) class fact_0(object): value = 1 class fact_meta(object): def

Re: Iteration for Factorials

2007-10-24 Thread [EMAIL PROTECTED]
On Oct 24, 4:05 pm, Lou Pecora <[EMAIL PROTECTED]> wrote: > In article <[EMAIL PROTECTED]>, > Nick Craig-Wood <[EMAIL PROTECTED]> wrote: > > > > > > > Py-Fun <[EMAIL PROTECTED]> wrote: > > > I'm stuck trying to write a function that generates a factorial of a > > > number using iteration and not

Re: Iteration for Factorials

2007-10-24 Thread Lou Pecora
In article <[EMAIL PROTECTED]>, Nick Craig-Wood <[EMAIL PROTECTED]> wrote: > Py-Fun <[EMAIL PROTECTED]> 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. > > Here is the mat

Re: Iteration for Factorials

2007-10-24 Thread Nick Craig-Wood
Py-Fun <[EMAIL PROTECTED]> 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. Here is the math geek answer ;-) import math def factorial(i): n = i + 1 return math.exp(-n)*(

Re: Iteration for Factorials

2007-10-24 Thread Hendrik van Rooyen
"Jon Ribbens" wrote: > On 2007-10-23, Hendrik van Rooyen <[EMAIL PROTECTED]> wrote: > > Yuk. Reminds me of one of the Hitachi processors that > > has a single depth hardware "link register" that tells a > > subroutine where it was called from. > > That's how ARM processors work, and they're e

Re: Iteration for Factorials

2007-10-23 Thread Marco Mariani
[EMAIL PROTECTED] wrote: > Needs work. Uh... ok.. this one gives an exception ;-) def fact(n): try: return eval('*'.join(str(x) for x in range(1,n+1))) except: return n>=0 or ValueError print fact(-1) -- http://mail.python.org/mailman/listinfo/python-list

Re: Iteration for Factorials

2007-10-23 Thread [EMAIL PROTECTED]
On Oct 23, 5:55 am, Marco Mariani <[EMAIL PROTECTED]> wrote: > Tim Chase wrote: > fact = lambda i: i > 1 and reduce(mul, xrange(1, i+1)) or not > > i and 1 or None > > > Stunts like this would get a person fired around here if they > > were found in production code :) > > eheh, indeed. > > def

Re: Iteration for Factorials

2007-10-23 Thread [EMAIL PROTECTED]
On Oct 23, 6:58 am, [EMAIL PROTECTED] wrote: > On 22 oct, 23:39, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > > > Nope, still doesn't work: > > > def fact(x): > > return reduce(operator.mul,xrange(1,x+1),1) > > > fact() should raise an exception if x is negative. > > So, where is the pr

Re: Iteration for Factorials

2007-10-23 Thread Marco Mariani
Roberto Bonvallet wrote: > import urllib > import re > urllib.URLopener.version = "Mozilla/4.0" > > def fact(x): > r = re.compile(r"%d ! = (\d+)" % x) > for line in urllib.urlopen("http://www.google.cl/search?q=%d%%21"; % x): > m = r.search(line) > if m: > retu

Re: Iteration for Factorials

2007-10-23 Thread Jon Ribbens
On 2007-10-23, Hendrik van Rooyen <[EMAIL PROTECTED]> wrote: > Yuk. Reminds me of one of the Hitachi processors that > has a single depth hardware "link register" that tells a > subroutine where it was called from. That's how ARM processors work, and they're everywhere these days. -- http://mai

Re: Iteration for Factorials

2007-10-23 Thread Hendrik van Rooyen
"Dennis Lee Bieber" <[EMAIL PROTECTED]> wrote: > > > Heh... the one saving grace of taking a CS major in a period where > the primary languages taught were FORTRAN (IV), COBOL (74), and > something close to K&K BASIC. Heck, even the assembler class followed > the FORTRAN parameter handling scheme

Re: Iteration for Factorials

2007-10-23 Thread Roberto Bonvallet
On Oct 22, 11:45 am, Ant <[EMAIL PROTECTED]> wrote: > Er, no. And neither is mine. You may want to google for the definition > of factorial! Don't google for the definition... google for the answer! import urllib import re urllib.URLopener.version = "Mozilla/4.0" def fact(x): r = re.compile(

Re: Iteration for Factorials

2007-10-23 Thread cokofreedom
On Oct 23, 1:58 pm, [EMAIL PROTECTED] wrote: > On 22 oct, 23:39, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > > > Nope, still doesn't work: > > > def fact(x): > > return reduce(operator.mul,xrange(1,x+1),1) > > > fact() should raise an exception if x is negative. > > So, where is the pr

Re: Iteration for Factorials

2007-10-23 Thread tokland
On 22 oct, 23:39, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > Nope, still doesn't work: > > def fact(x): > return reduce(operator.mul,xrange(1,x+1),1) > > fact() should raise an exception if x is negative. So, where is the problem? if not allowing negative numbers is so important for

Re: Iteration for Factorials

2007-10-23 Thread Marco Mariani
Tim Chase wrote: fact = lambda i: i > 1 and reduce(mul, xrange(1, i+1)) or not > i and 1 or None > > Stunts like this would get a person fired around here if they > were found in production code :) eheh, indeed. def fact(n): try: return eval('*'.join(str(x) for x in range(1,

Re: Iteration for Factorials

2007-10-23 Thread cokofreedom
On Oct 23, 8:53 am, "Hendrik van Rooyen" <[EMAIL PROTECTED]> wrote: > "Marco Mariani" wrote: > > > I don't see how my answer is in any way worse than those based on > > lambda. Maybe I'm just envious because when I was his age I couldn't > > google for answers. He should at least be able to do th

Re: Iteration for Factorials

2007-10-23 Thread Hendrik van Rooyen
"Marco Mariani" wrote: > I don't see how my answer is in any way worse than those based on > lambda. Maybe I'm just envious because when I was his age I couldn't > google for answers. He should at least be able to do that, shouldn't he? > But wait. That would mean understanding what a factori

Re: Iteration for Factorials

2007-10-22 Thread Mensanator
In a message dated 10/22/2007 8:46:59 PM Central Daylight Time, [EMAIL PROTECTED] writes: > > Still, why do you want None instead of raisng an exception > > (as is the case in other factorial implementations)? > > A null value is as good/bad as raising an exception in my book. > Since you can'

Re: Iteration for Factorials

2007-10-22 Thread Tim Chase
> Still, why do you want None instead of raisng an exception > (as is the case in other factorial implementations)? A null value is as good/bad as raising an exception in my book. Since you can't do math on a None object, any attempt to do so will raise an exception: >>> 42 + fact(-1) I genera

Re: Iteration for Factorials

2007-10-22 Thread [EMAIL PROTECTED]
On Oct 22, 5:39 pm, Tim Chase <[EMAIL PROTECTED]> wrote: > >> If obscurity is the name of the game, > > >>>>> from operator import mul > >>>>> fact = lambda i: i > 1 and reduce(mul, xrange(1,i+1)) or i > >> >= 0 and 1 or None > >>>>> for i in xrange(-2,10): print '%i! = %s' % (i, fact(

Re: Iteration for Factorials

2007-10-22 Thread Tim Chase
>> If obscurity is the name of the game, >> >>>>> from operator import mul >>>>> fact = lambda i: i > 1 and reduce(mul, xrange(1,i+1)) or i >> >= 0 and 1 or None >>>>> for i in xrange(-2,10): print '%i! = %s' % (i, fact(i)) >> >> My eyes hurt after reading that...as the order of operat

Re: Iteration for Factorials

2007-10-22 Thread [EMAIL PROTECTED]
On Oct 22, 4:39 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > On Oct 22, 3:38 pm, Paul Rudin <[EMAIL PROTECTED]> wrote: > > > > > > > [EMAIL PROTECTED] writes: > > > On 22 oct, 20:35, Paul Rudin <[EMAIL PROTECTED]> wrote: > > > >> import operator > > >> def fact(x): > > >> return reduce(

Re: Iteration for Factorials

2007-10-22 Thread [EMAIL PROTECTED]
On Oct 22, 3:22 pm, Tim Chase <[EMAIL PROTECTED]> wrote: > > def fact(x): > > if x == 0 or x == 1: > > return 1 > > else: > > return reduce(operator.mul, xrange(1,x+1)) > > If obscurity is the name of the game, > >>>> from operator import mul >>>> fact = lambda i: i

Re: Iteration for Factorials

2007-10-22 Thread [EMAIL PROTECTED]
On Oct 22, 3:38 pm, Paul Rudin <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] writes: > > On 22 oct, 20:35, Paul Rudin <[EMAIL PROTECTED]> wrote: > > >> import operator > >> def fact(x): > >> return reduce(operator.mul, xrange(1,x)) > > > Maybe: > > > import operator > > def fact(x): > > re

Re: Iteration for Factorials

2007-10-22 Thread Paul Rudin
[EMAIL PROTECTED] writes: > On 22 oct, 20:35, Paul Rudin <[EMAIL PROTECTED]> wrote: > >> import operator >> def fact(x): >> return reduce(operator.mul, xrange(1,x)) > > Maybe: > > import operator > def fact(x): > return reduce(operator.mul, xrange(2, x+1), 1) Or just: reduce(operator.mul

Re: Iteration for Factorials

2007-10-22 Thread Tim Chase
> def fact(x): > if x == 0 or x == 1: > return 1 > else: > return reduce(operator.mul, xrange(1,x+1)) If obscurity is the name of the game, >>> from operator import mul >>> fact = lambda i: i > 1 and reduce(mul, xrange(1,i+1)) or i >= 0 and 1 or None >>> for i i

Re: Iteration for Factorials

2007-10-22 Thread tokland
On 22 oct, 20:35, Paul Rudin <[EMAIL PROTECTED]> wrote: > import operator > def fact(x): > return reduce(operator.mul, xrange(1,x)) Maybe: import operator def fact(x): return reduce(operator.mul, xrange(2, x+1), 1) fact(0) 1 fact(4) 24 -- http://mail.python.org/mailman/listinfo/python

Re: Iteration for Factorials

2007-10-22 Thread Rafael Sachetto
This works: def fact(x): if x == 0 or x == 1: return 1 else: return reduce(operator.mul, xrange(1,x+1)) or def factorial(n): acc = 1 while n > 1: acc = acc * n n = n - 1 return acc On 10/22/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > O

Re: Iteration for Factorials

2007-10-22 Thread [EMAIL PROTECTED]
On Oct 22, 1:35 pm, Paul Rudin <[EMAIL PROTECTED]> wrote: > "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes: > > On Oct 22, 7:50 am, Duncan Booth <[EMAIL PROTECTED]> wrote: > >> Py-Fun <[EMAIL PROTECTED]> wrote: > >> > I'm stuck trying to write a function that generates a factorial of a > >> > numbe

Re: Iteration for Factorials

2007-10-22 Thread Steven Bethard
Michael J. Fromberger wrote: > # Not legal Python code. > def fact3(n, acc = 1): > TOP: > if n > 0 > n = n - 1 > acc = acc * n > goto TOP > else: > return acc Yes, to write this in legal Python code, you have to write:: from goto import goto

Re: Iteration for Factorials

2007-10-22 Thread Rafael Sachetto
The right way is: import operator def fact(x): return reduce(operator.mul, xrange(1,x+1)) On 10/22/07, Paul Rudin <[EMAIL PROTECTED]> wrote: > > "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes: > > > On Oct 22, 7:50 am, Duncan Booth <[EMAIL PROTECTED]> wrote: > >> Py-Fun <[EMAIL PROTECTED]> wro

Re: Iteration for Factorials

2007-10-22 Thread Paul Rudin
"[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes: > On Oct 22, 7:50 am, Duncan Booth <[EMAIL PROTECTED]> wrote: >> Py-Fun <[EMAIL PROTECTED]> 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 >>

Re: Iteration for Factorials

2007-10-22 Thread Michael J. Fromberger
In article <[EMAIL PROTECTED]>, Py-Fun <[EMAIL PROTECTED]> 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. Well, first think about the recursive implementation: def fact(n):

Re: Iteration for Factorials

2007-10-22 Thread [EMAIL PROTECTED]
On Oct 22, 7:50 am, Duncan Booth <[EMAIL PROTECTED]> wrote: > Py-Fun <[EMAIL PROTECTED]> 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. > > This version avoids doing anything f

Re: Iteration for Factorials

2007-10-22 Thread Tim Golden
Marco Mariani wrote: > Tim Golden wrote: > >>> From the cookbook, this time. >>> It satisfies the requirements nicely ;) >>> >>> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496691 >> [... snip the ultimate general-purpose answer to the OP's question ... >> >> I really hope that's a w

Re: Iteration for Factorials

2007-10-22 Thread Paul McGuire
On Oct 22, 8:02 am, vimal <[EMAIL PROTECTED]> wrote: > On Oct 22, 5:43 pm, 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

Re: Iteration for Factorials

2007-10-22 Thread Peter Goodman
On Oct 22, 8:26 am, Py-Fun <[EMAIL PROTECTED]> 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. def fac_btt(num): total = 1 if num > 1: for i in range(

Re: Iteration for Factorials

2007-10-22 Thread Marco Mariani
Tim Golden wrote: >> From the cookbook, this time. >> It satisfies the requirements nicely ;) >> >> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496691 > > [... snip the ultimate general-purpose answer to the OP's question ... > > I really hope that's a wink up there, Marco. The wi

Re: Iteration for Factorials

2007-10-22 Thread Tim Golden
Marco Mariani wrote: > From the cookbook, this time. > It satisfies the requirements nicely ;) > > > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496691 > [... snip the ultimate general-purpose answer to the OP's question ... I really hope that's a wink up there, Marco. The poor g

Re: Iteration for Factorials

2007-10-22 Thread Marco Mariani
From the cookbook, this time. It satisfies the requirements nicely ;) http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496691 def tail_recursion(g): ''' Version of tail_recursion decorator using no stack-frame inspection. ''' loc_vars ={"in_loop":False,"cnt":0}

Re: Iteration for Factorials

2007-10-22 Thread Ant
On Oct 22, 1:26 pm, Py-Fun <[EMAIL PROTECTED]> 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. The following simple adder functions should give you an idea of how recursion can be re

Re: Iteration for Factorials

2007-10-22 Thread vimal
On Oct 22, 5:43 pm, 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

Re: Iteration for Factorials

2007-10-22 Thread Amit Khemka
On 10/22/07, Py-Fun <[EMAIL PROTECTED]> wrote: > 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.

Re: Iteration for Factorials

2007-10-22 Thread cokofreedom
On Oct 22, 2:43 pm, 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

Re: Iteration for Factorials

2007-10-22 Thread Py-Fun
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 t

Re: Iteration for Factorials

2007-10-22 Thread Duncan Booth
Py-Fun <[EMAIL PROTECTED]> 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. > This version avoids doing anything fancier than adding 1, so it should be simple enough for anyone: de

Re: Iteration for Factorials

2007-10-22 Thread Marco Mariani
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. -- http://mail.python.org/mailman/listinfo/python-list

Re: Iteration for Factorials

2007-10-22 Thread Marco Mariani
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? -- http://mail.python.org/mailman/listinfo/python-list

Re: Iteration for Factorials

2007-10-22 Thread Py-Fun
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. B

Re: Iteration for Factorials

2007-10-22 Thread Diez B. Roggisch
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 -- http://

Iteration for Factorials

2007-10-22 Thread 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. -- http://mail.python.org/mailman/listinfo/python-list