Jump to content

Recommended Posts

Posted

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]?

Posted

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.

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.