Factorial-code issues


#1



https://www.codecademy.com/courses/python-intermediate-en-rCQKw/0/5?curriculum_id=4f89dab3d788890003000096#


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


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


#2

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.


#3

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


#4

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


#5

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


#6

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.


#7

working it out..thanks for the hint


#9

This site is very helpful:


#11

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