Code for finding a number factorial


In python course:
Lesson: 'Practice Makes Perfect' / exercise 5. factorial
When i try the code below it finds the correct result but i get the warning:
'Ops, try again. factorial(1) returned None, did you remember to return the result?'
The code:

def factorial(x):
    for i in range(x+1):
    print a
    for item in a:
    print result    

factorial(0) returns 1,
factorial(1) returns 1,
factorial(5) returns 120
as expected
So, i would like to know where i am failing. Many thanks for the help in advance.


Maybe instead of printing you should be returning?


oh...sorry for the lame question, it worked. thanks mattaveleira


we all have been there hahah. Your welcome :smiley:


I think this is a mistake from codeacademy and I will try to pass this by doing it the hard way. But if you try this it lets you pass lool:

import math
def factorial(x):
..... return math.factorial(x):


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