use the accumulator patternmake sure you include the proper initialization forgetting this is common mistake of beginning programmers of coursethere are many other ways we could have written this loop as you know from math classmultiplication is commutative and associativeso it really doesn' matter what order we do the multiplications in we could just as easily go the other direction you might also notice that including in the list of factors is unnecessarysince multiplication by does not change the result here is another version that computes the same resultfact for factor in [ , , , , ]fact fact factor unfortunatelyneither of these loops solves the original problem we have hand-coded the list of factors to compute the factorial of six what we really want is program that can compute the factorial of any given input we need some way to generate an appropriate sequence of factors from the value of luckilythis is quite easy to do using the python range function recall that range(nproduces sequence of numbers starting with and continuing up tobut not includingn there are other variations of range that can be used to produce different sequences with two parametersrange(start,nproduces sequence that starts with the value start and continues up tobut does not includen third version range(startnstepis like the two-parameter versionexcept that it uses step as the increment between numbers here are some exampleslist(range( )[ list(range( , )[ list(range( )[ given our input value we have couple of different range commands that produce an appropriate list of factors for computing the factorial of to generate them from smallest to largest ( la our second loop)we could use range( , + notice how used + as the second parametersince the range will go up to but not include this value we need the + to make sure that itself is included as the last factor another possibility is to generate the factors in the other direction ( la our first loopusing the three-parameter version of range and negative step to cause the counting to go backwardsrange( , ,- this one produces list starting with and counting down (step - tobut not including here then is one possible version of the factorial programfactorial py