School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 307,216 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,575 people online right now. Registration is fast and FREE... Join Now!




Geometric Progression

 

Geometric Progression, Looping Excercise

EthanR

10 Sep, 2009 - 04:09 PM
Post #1

New D.I.C Head
*

Joined: 19 Mar, 2009
Posts: 12

A geometric progression is a sequence of numbers in which each value (after the first) is obtained by multiplying the previous value 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 .

I am trying this problem using a For loop but I think my types might be mixed around I am not 100% sure on writing to a list but here is my code but it is incorrect.

geom_prog = 0
for i in range(1,n+1):
geom_prog += i * ratio



User is offlineProfile CardPM
+Quote Post


shadhin

RE: Geometric Progression

10 Sep, 2009 - 04:45 PM
Post #2

D.I.C Regular
Group Icon

Joined: 16 Sep, 2008
Posts: 434



Thanked: 19 times
Dream Kudos: 3650
My Contributions
Are you looking for something like this?
CODE

n=int(raw_input("Enter n:"))
r=int(raw_input("Enter common ratio:"))
geom_prog=[1]
li=1
while li<n:
    li *= r
    geom_prog.append(li)

print geom_prog

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 10:04PM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month