Python Forum
computing the factorial of N
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
computing the factorial of N
#12
Well, if we're doing factorials, I have to give my evil answer:

def factorial(n, factorials = [1, 1, 2, 6, 24]):
    while n + 1 > len(factorials):
        factorials.append(factorials[-1] *  len(factorials))
    return factorials[n]
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Messages In This Thread
computing the factorial of N - by foolsgold27 - Jun-01-2017, 02:19 PM
RE: HELP SOLVING SIMPLE PYTHON PROBLEM - by Turry - Jun-01-2017, 03:54 PM
RE: HELP SOLVING SIMPLE PYTHON PROBLEM - by prog92 - Jun-01-2017, 05:56 PM
RE: HELP SOLVING SIMPLE PYTHON PROBLEM - by nilamo - Jun-01-2017, 07:06 PM
RE: HELP SOLVING SIMPLE PYTHON PROBLEM - by wavic - Jun-02-2017, 06:36 AM
RE: HELP SOLVING SIMPLE PYTHON PROBLEM - by wavic - Jun-02-2017, 08:27 AM
RE: computing the factorial of N - by martan45 - Aug-01-2017, 07:58 PM
RE: computing the factorial of N - by nilamo - Aug-01-2017, 08:08 PM
RE: computing the factorial of N - by martan45 - Aug-01-2017, 08:16 PM
RE: computing the factorial of N - by nilamo - Aug-01-2017, 08:30 PM
RE: computing the factorial of N - by ichabod801 - Aug-02-2017, 02:16 AM
RE: computing the factorial of N - by nilamo - Aug-02-2017, 02:29 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Python Program to Find the Factorial of a Number elisahill 2 1,503 Nov-21-2022, 02:25 PM
Last Post: DeaD_EyE
  computing average in nested loops cap510 5 5,257 Sep-11-2020, 12:33 PM
Last Post: deanhystad
  Fork the process (factorial) vndywarhol 3 3,458 Sep-07-2018, 03:28 AM
Last Post: ichabod801
  Computing average vestkok 2 2,555 Aug-12-2018, 10:02 AM
Last Post: vestkok
  Computing factorials Truman 6 4,177 Mar-14-2018, 06:38 AM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020