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

  2. vimal

    Amit Khemka Guest

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

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

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:
    12,765
    Boris Stumm
    Feb 9, 2006
  2. Replies:
    46
    Views:
    997
    Antoon Pardon
    Jul 25, 2006
  3. Lambda
    Replies:
    2
    Views:
    424
    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:
    171
    Tomoyuki Kosimizu
    Nov 27, 2003
  5. David Bird
    Replies:
    1
    Views:
    244
    Tiago Macedo
    Jun 23, 2008
Loading...

Share This Page