Requoter Posted September 15, 2008 Posted September 15, 2008 I'm new to Python, and while doing homework I got stuck on this little problem. We were supposed to output various sequnces of numbers using for loops and range functions. I did all of them except the last one which I can't figure out. How do you output the following sequence: [1, 2, 6, 24, 120, 720]?
Cap'n Refsmmat Posted September 15, 2008 Posted September 15, 2008 Aha. The sequence looks like it was generated by looping with a loop variable (let's say i) that increases by one each time. Each new number in the sequence is generated by multiplying the previous number by i. So you start at one, multiply by two, then take two and multiply by three, and so on. So all you need is a loop with a variable that increases by one each time and a variable storing the previous number in the sequence.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now