Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #68827 > unrolled thread
| Started by | pabloeruggeri@gmail.com |
|---|---|
| First post | 2014-03-23 17:35 -0700 |
| Last post | 2014-03-24 13:31 +1100 |
| Articles | 12 — 8 participants |
Back to article view | Back to comp.lang.python
loop pabloeruggeri@gmail.com - 2014-03-23 17:35 -0700
Re: loop MRAB <python@mrabarnett.plus.com> - 2014-03-24 00:50 +0000
Re: loop pabloeruggeri@gmail.com - 2014-03-23 17:57 -0700
Re: loop Chris Angelico <rosuav@gmail.com> - 2014-03-24 11:52 +1100
Re: loop Marko Rauhamaa <marko@pacujo.net> - 2014-03-24 09:47 +0200
Re: loop Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-03-24 09:40 +0000
Re: loop Marko Rauhamaa <marko@pacujo.net> - 2014-03-24 12:04 +0200
Re: loop Chris Angelico <rosuav@gmail.com> - 2014-03-24 21:58 +1100
Re: loop Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-03-24 00:56 +0000
Re: loop anton <bupphairodazz@yandex.ru> - 2014-03-23 17:59 -0700
Re: loop Mark H Harris <harrismh777@gmail.com> - 2014-03-23 22:30 -0500
Re: loop Ben Finney <ben+python@benfinney.id.au> - 2014-03-24 13:31 +1100
| From | pabloeruggeri@gmail.com |
|---|---|
| Date | 2014-03-23 17:35 -0700 |
| Subject | loop |
| Message-ID | <e2be2ed8-e2b8-427c-b826-e7240ecc5bdf@googlegroups.com> |
Hello, I'm trying to create a for loop that starts at 100 and goes to 10Mllion. The increments are like this: 100, 1000, 10000, ..... Basicaly adding a zero each iteration. I'm having problems trying to do it. Can somebody help me
[toc] | [next] | [standalone]
| From | MRAB <python@mrabarnett.plus.com> |
|---|---|
| Date | 2014-03-24 00:50 +0000 |
| Message-ID | <mailman.8425.1395622263.18130.python-list@python.org> |
| In reply to | #68827 |
On 2014-03-24 00:35, pabloeruggeri@gmail.com wrote: > Hello, > > I'm trying to create a for loop that starts at 100 and goes to > 10Mllion. The increments are like this: 100, 1000, 10000, ..... > Basicaly adding a zero each iteration. I'm having problems trying to > do it. Can somebody help me > Probably better to use a 'while' loop instead, multiplying by 10 on each iteration until the number exceeds 10 million.
[toc] | [prev] | [next] | [standalone]
| From | pabloeruggeri@gmail.com |
|---|---|
| Date | 2014-03-23 17:57 -0700 |
| Message-ID | <fd3d0d6e-caf0-4b42-bae1-a4be752b40a9@googlegroups.com> |
| In reply to | #68828 |
Thanks!!
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2014-03-24 11:52 +1100 |
| Message-ID | <mailman.8426.1395622335.18130.python-list@python.org> |
| In reply to | #68827 |
On Mon, Mar 24, 2014 at 11:35 AM, <pabloeruggeri@gmail.com> wrote: > Hello, > > I'm trying to create a for loop that starts at 100 and goes to 10Mllion. The increments are like this: 100, 1000, 10000, ..... Basicaly adding a zero each iteration. I'm having problems trying to do it. Can somebody help me > That sounds like a logarithmic scale. Look at this: >>> 10**2 100 >>> 10**3 1000 ... >>> 10**7 10000000 Do you know how to iterate from 2 to 7 inclusive? ChrisA
[toc] | [prev] | [next] | [standalone]
| From | Marko Rauhamaa <marko@pacujo.net> |
|---|---|
| Date | 2014-03-24 09:47 +0200 |
| Message-ID | <87fvm811i7.fsf@elektro.pacujo.net> |
| In reply to | #68829 |
Chris Angelico <rosuav@gmail.com>:
> On Mon, Mar 24, 2014 at 11:35 AM, <pabloeruggeri@gmail.com> wrote:
>> I'm trying to create a for loop that starts at 100 and goes to 10Mllion.
>
> That sounds like a logarithmic scale.
How about:
for i in [ 100, 1000, 10000, 100000, 1000000, 10000000, 100000000 ]:
...
Marko
[toc] | [prev] | [next] | [standalone]
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Date | 2014-03-24 09:40 +0000 |
| Message-ID | <mailman.8441.1395654073.18130.python-list@python.org> |
| In reply to | #68854 |
On 24/03/2014 07:47, Marko Rauhamaa wrote: > Chris Angelico <rosuav@gmail.com>: > >> On Mon, Mar 24, 2014 at 11:35 AM, <pabloeruggeri@gmail.com> wrote: >>> I'm trying to create a for loop that starts at 100 and goes to 10Mllion. >> >> That sounds like a logarithmic scale. > > How about: > > for i in [ 100, 1000, 10000, 100000, 1000000, 10000000, 100000000 ]: > ... Why the overhead of creating a list when you could use a tuple? :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com
[toc] | [prev] | [next] | [standalone]
| From | Marko Rauhamaa <marko@pacujo.net> |
|---|---|
| Date | 2014-03-24 12:04 +0200 |
| Message-ID | <877g7j29qn.fsf@elektro.pacujo.net> |
| In reply to | #68856 |
Mark Lawrence <breamoreboy@yahoo.co.uk>: > On 24/03/2014 07:47, Marko Rauhamaa wrote: >> for i in [ 100, 1000, 10000, 100000, 1000000, 10000000, 100000000 ]: > > Why the overhead of creating a list when you could use a tuple? :) Once in college, we were given assembly programming assignments. The textbook defined an imagined 18-bit CPU and an instruction set. A fellow student was given the task to write a subroutine that calculates the factorial of the argument. He went through the trouble of creating a loop with multiplication etc. I argued (in vain) that his solution is "wrong" from all angles; he should have implemented his subroutine with a simple lookup table since 18 bits can only take a handful of input values (0 through 8). Marko
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2014-03-24 21:58 +1100 |
| Message-ID | <mailman.8444.1395658712.18130.python-list@python.org> |
| In reply to | #68861 |
On Mon, Mar 24, 2014 at 9:04 PM, Marko Rauhamaa <marko@pacujo.net> wrote: > Once in college, we were given assembly programming assignments. The > textbook defined an imagined 18-bit CPU and an instruction set. > > A fellow student was given the task to write a subroutine that > calculates the factorial of the argument. He went through the trouble of > creating a loop with multiplication etc. I argued (in vain) that his > solution is "wrong" from all angles; he should have implemented his > subroutine with a simple lookup table since 18 bits can only take a > handful of input values (0 through 8). The task was "calculates". If the task was "returns", then the lookup table would be correct. :) ChrisA
[toc] | [prev] | [next] | [standalone]
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Date | 2014-03-24 00:56 +0000 |
| Message-ID | <mailman.8427.1395622631.18130.python-list@python.org> |
| In reply to | #68827 |
On 24/03/2014 00:35, pabloeruggeri@gmail.com wrote: > Hello, > > I'm trying to create a for loop that starts at 100 and goes to 10Mllion. The increments are like this: 100, 1000, 10000, ..... Basicaly adding a zero each iteration. I'm having problems trying to do it. Can somebody help me > Start by rereading this http://docs.python.org/3/tutorial/controlflow.html#for-statements, give it another go and if you have problems post your code inline here and we'll help you out. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com
[toc] | [prev] | [next] | [standalone]
| From | anton <bupphairodazz@yandex.ru> |
|---|---|
| Date | 2014-03-23 17:59 -0700 |
| Message-ID | <05924f21-0162-4d4c-84d0-016c7fdfeee1@googlegroups.com> |
| In reply to | #68827 |
for i in (10**p for p in range(3, 8)):
print(i)
[toc] | [prev] | [next] | [standalone]
| From | Mark H Harris <harrismh777@gmail.com> |
|---|---|
| Date | 2014-03-23 22:30 -0500 |
| Message-ID | <lgo8td$92p$2@speranza.aioe.org> |
| In reply to | #68832 |
On 3/23/14 7:59 PM, anton wrote: > for i in (10**p for p in range(3, 8)): > print(i) Never do their home-work for them; but, in this case, what the heck. :)
[toc] | [prev] | [next] | [standalone]
| From | Ben Finney <ben+python@benfinney.id.au> |
|---|---|
| Date | 2014-03-24 13:31 +1100 |
| Message-ID | <mailman.8432.1395628275.18130.python-list@python.org> |
| In reply to | #68827 |
pabloeruggeri@gmail.com writes: > I'm trying to create a for loop that starts at 100 and goes to > 10Mllion. The increments are like this: 100, 1000, 10000, ..... > Basicaly adding a zero each iteration. I'm having problems trying to > do it. Can somebody help me Welcome. What have you tried so far? We're not in the practice of just writing the code for you; please show us what you have written that we can try running it, and how it's behaving differently from what you expect. -- \ “Oh, I love your magazine. My favorite section is ‘How To | `\ Increase Your Word Power’. That thing is really, really, | _o__) really... good.” —Homer, _The Simpsons_ | Ben Finney
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web