5. Factorial


I get 1 as a result regardless of what I put in.
I'm assuming this means my code is not looping; however I can't figure out which part is causing this.

def factorial(x):
    for i in range(x):
        result = 1
        if i > 0 :
            while i > 0:
                result == result * i
                i += 1
            return result    
            return result


@domini04 ,

What is the purpose of this statement? ...

result == result * i

Is it written correctly to perform its task?


You have two loops, that makes me want to suggest that you re-read what factorial is - I think you'll have a hard time motivating why they are both required

You may well know what factorial is, point is that you should also see that two loops don't make much sense and that the next thing to do is to reconsider what actions are required and in what order


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