loop

P

pabloeruggeri

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
 
M

MRAB

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.
 
C

Chris Angelico

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:
1000
....
10000000

Do you know how to iterate from 2 to 7 inclusive?

ChrisA
 
M

Marko Rauhamaa

Chris Angelico said:
That sounds like a logarithmic scale.

How about:

for i in [ 100, 1000, 10000, 100000, 1000000, 10000000, 100000000 ]:
...


Marko
 
M

Marko Rauhamaa

Mark Lawrence said:
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
 
C

Chris Angelico

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,157
Latest member
MercedesE4
Top