1. This forum is in read-only mode.

i need some help with python programming.!!!!!!!!!!!!!!!!!!!

Discussion in 'Computers & Modding' started by zzzzzzzzzz, Sep 19, 2009.

  1. zzzzzzzzzz

    zzzzzzzzzz Member

    A geometric progression is a sequence of numbers in which each value (after the first) is obtained by multiplying the previosuvalue in the sequence by a fixed value called the common ratio. For example the sequence 3, 12, 48, 192, ... is a geometric progression in which the common ratio is 4.

    Given the positive integer ratio greater than 1, and the non-negative integer n , create a list consisting of the geometric progression of numbers between (and including) 1 and n with a common ratio of ratio . For example, if ratio is 2 and n is 8, the list would be [1, 2, 4, 8] .

    Associate the list with the variable geom_prog .

    ---------------HOW DO I DO THE ABOVE QUESTION????-----------------------------

    here is a kind of similar task

    Assume there is a variable, h already associated with a positive integer value. Write the code necessary to compute the sum of the first h perfect squares, starting with 1 . (A perfect square is an integer like 9 , 16 , 25 , 36 that is equal to the square of another integer (in this case 3*3 , 4*4 , 5*5 , 6*6 respectively).) Associate the sum you compute with the variable q . For example, if h is 4 , you would assign 30 to q because the first 4 perfect squares (starting with 1 ) are: 1 , 4 , 9 , 16 and 30==1+4+9+16 .

    ANSWER FOR THIS ONE IS
    q=0
    for i in range(1,h+1):
    q +=i**2

    --------------HERE IS ANOTHER TASK-------------------------------------------
    An arithmetic progression is a sequence of numbers in which the distance (or difference) between any two successive numbers if the same. This in the sequence 1, 3, 5, 7, ... , the distance is 2 while in the sequence 6, 12, 18, 24, ... , the distance is 6.

    Given the positive integer distance and the non-negative integer n , create a list consisting of the arithmetic progression between (and including) 1 and n with a distance of distance . For example, if distance is 2 and n is 8, the list would be [1, 3, 5, 7] .

    Associate the list with the variable arith_prog .

    HERE IS THE ANSWER
    arith_prog = range(1, (n+1), distance)





    MAYBE USING THE SECOND AND THIRD EXAMPLES, YOU CAN HELP SOLVE THE FIRST QUESTION, BECAUSE I AM LOST AT IT.............
     
  2. Loonylion

    Loonylion Administrator Staff Member

    This sounds to me more like you're having issues with the actual math formulae, not the python language itself.