2

Can you nested the range in range? Use variable in range? Because I would like to get some effect. To illustrate the problem I have the following pseudocode:

for i in range(str(2**i) for i in range(1,2)):
    print (str(i*0.01))

At the exit I would like to receive:

0   0.01
1   0.01
2   0.02
3   0.02
4   0.02
5   0.02

Where the number of numbers 0.01 in the column will be 2^1, the number of numbers 0.02 are 2^2, the number of numbers 0.03 are 2^3, and so on ... I will be grateful for any hint as to how to approach this.

1
  • This raises more self-referential questions than it should :) Commented Nov 16, 2017 at 20:01

1 Answer 1

4

For this specific task you'll want to nest them like this:

for i in range(1,3):
    for j in range(2**i):
        print(i * 0.01)

which will print what you want. What this is doing is taking a number i in range(1,3) #[1,2] and then print i * 0.01 2**i number of times which I believe is what you are trying to do.

Sign up to request clarification or add additional context in comments.

1 Comment

That's exactly what it was. Thank you very much!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.