Jump to content

Need Python help

Featured Replies

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

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.

Archived

This topic is now archived and is closed to further replies.

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.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.