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]?
Welcome to ScienceForums.Net!
|
After you've registered, come in and introduce yourself, or visit the forum index. If you need any help registering, posting, or if you just have some questions about our site, please feel free to contact us at staff at scienceforums dot net.
|
|
| Guest Message © 2012 DevFuse | |
Page 1 of 1
Need Python help
#2 15 September 2008 - 04:49 AM
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.
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.
- Posts: 11,433 | Joined: 04-January 04
Reply
Share this topic:
Page 1 of 1

Help
Sign In »
Register Now!











