Correct return but it gets rejected. please help


#1



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


It tells me that my function returns a wrong value, but it doesn't? What is going on here?
I get a "Oops, try again. factorial(1) returned 6 instead of 1" while you can see in the screenshot it returned a 1.

I tried it with other values. For example if you test my function with the value "4" it returns 24 which is correct but I'll get the error "Oops, try again. factorial(4) returned 48 instead of 24"


This should work right?


fact_list = []

def factorial(x):
    calc = x
    fact = x
    while calc > 1:
        fact_list.append(calc)
        calc -= 1
    else:
        for i in fact_list:
            fact = fact * (i - 1)
    return fact


print factorial(1)
print factorial(4)


#2

the exercise calls the function multiply times, to check it works correctly

this means, everything should go inside your function


#3

I get that it calls the function multiple times with different values for x. But any value for x returns the correct value. The print you see at the bottom of my code is just a test.

The weird thing is that the error says that my function returns a 6 instead of 1 when x = 1 however if I run my function with x = 1 I get returned: 1, not 6.


#4

you should place this line:

fact_list = []

inside the function, the exercise will execute many function calls


#5

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