Code for finding a number factorial


#1

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):
    a=[]
    result=1
    for i in range(x+1):
        a.append(i)
    a.pop(0)
    print a
    for item in a:
        result*=item
    print result    
factorial(0)

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.


#2

Maybe instead of printing you should be returning?


#3

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


#4

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


#5

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):


#6

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