Factorial


#1



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


right now factorial(3) is returning 3 instead of six. It appears my loop is resetting count each time like
count = 1*2 >> count = 1*3
rather then
count = 1*2 >> count = 2*3


num = input("enter your number: ")
def factorial(x):
    count = 1
    if x <= 1:
       return 1
    else: 
       for i in range(x):
           count = count * (count + 1)
       return x


#2

Zero is included in this range,

x is unchanged.


#3

I switched x to count since that is the value I am trying to return and now factorial(2) = 6?


#5

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