Science Forums: Need Python help - Science Forums

Jump to content

Welcome to ScienceForums.Net!

Welcome to ScienceForums.Net! We welcome science discussion at all levels — from beginners to researchers, covering topics from biology to computer science, and much more. Registration is fast and free, and allows you to post on the forums, so register now and join the discussions!
  
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.

  • Start new topics and reply to others
  • Subscribe to topics and forums to get automatic updates
  • Create a ScienceForums.Net Blog!
Guest Message © 2012 DevFuse
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Need Python help Rate Topic: -----

#1 Requoter 


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

#2 Cap'n Refsmmat 


Icon
Mr. Wizard
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.
Cap'n Refsmmat
SFN Administrator

Get in the chatroom!
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users