generating range of numbers

Discussion in 'Python' started by vimal, Oct 3, 2007.

  1. vimal

    vimal Guest

    hi all,

    i am new to python.....
    i just want to generate numbers in the form like:

    1,2,4,8,16,32.....to a maximum of 1024

    using a range function
     
    vimal, Oct 3, 2007
    #1
    1. Advertisements

  2. vimal

    Amit Khemka Guest

    Amit Khemka, Oct 3, 2007
    #2
    1. Advertisements

  3. On Oct 3, 2007, at 2:18 AM, vimal wrote:

    > i am new to python.....
    > i just want to generate numbers in the form like:
    >
    > 1,2,4,8,16,32.....to a maximum of 1024
    >
    > using a range function


    I don't think it can be done with *only* a range function...

    import math
    [pow(2, x) for x in range(math.log(1024, 2) +1)]

    hth,
    Michael
    ---
    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it. --Brian W. Kernighan
     
    Michael Bentley, Oct 3, 2007
    #3
  4. vimal wrote:
    > hi all,
    >
    > i am new to python.....
    > i just want to generate numbers in the form like:
    >
    > 1,2,4,8,16,32.....to a maximum of 1024
    >
    > using a range function
    >

    Homework?

    /W
     
    Wildemar Wildenburger, Oct 3, 2007
    #4
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    3
    Views:
    13,892
    Boris Stumm
    Feb 9, 2006
  2. Replies:
    46
    Views:
    1,356
    Antoon Pardon
    Jul 25, 2006
  3. Lambda
    Replies:
    2
    Views:
    594
    James Kanze
    Jul 16, 2008
  4. Tomoyuki Kosimizu

    Range does not take an Range object.

    Tomoyuki Kosimizu, Nov 25, 2003, in forum: Ruby
    Replies:
    3
    Views:
    290
    Tomoyuki Kosimizu
    Nov 27, 2003
  5. David Bird
    Replies:
    1
    Views:
    502
    Tiago Macedo
    Jun 23, 2008
  6. Joey Zhou
    Replies:
    5
    Views:
    448
    Joey Zhou
    Apr 15, 2011
  7. it_says_BALLS_on_your forehead

    extract range of lines using range op bug?

    it_says_BALLS_on_your forehead, Mar 3, 2006, in forum: Perl Misc
    Replies:
    3
    Views:
    361
    it_says_BALLS_on_your forehead
    Mar 3, 2006
  8. Replies:
    2
    Views:
    433
Loading...