Factorial-code issues



The code is responding with "factorial(2) returned 1 instead of 2." Trying to figure out what I did incorrectly.

def factorial(x):
    for i in range(x):
        if x<=1:
            return x
            while i>=x:
            return total


That is a lot of looping to reduce the sequence to a product. One loop should suffice, namely, the while loop. Be sure the final return is not inside a loop body.


am totally unable to figure out this factorial stuff....totally off..help please. am stuck


Then your math skills are what is in question. You need to address that for this exercise to make any sense,


i understand factorization , which is a maths skills...but to put the same in codes is now the issue here...give me a small hint please


This is not about factoring, but multiplying out a sequence from 0! to N. (0! is 1)

Iterate the values from one to n and accumulate the multiple.


working it out..thanks for the hint


This site is very helpful:


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.