0% found this document useful (0 votes)
33 views3 pages

Module 3 Code

The document provides an algorithm and Python code to generate the first six terms of a geometric progression starting from 20 with a common ratio of 0.5. It outlines the steps to initialize the first term, set the common ratio, and loop to compute the terms. The code defines a function to create the sequence and prints the resulting geometric progression.

Uploaded by

raghav122006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views3 pages

Module 3 Code

The document provides an algorithm and Python code to generate the first six terms of a geometric progression starting from 20 with a common ratio of 0.5. It outlines the steps to initialize the first term, set the common ratio, and loop to compute the terms. The code defines a function to create the sequence and prints the resulting geometric progression.

Uploaded by

raghav122006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Q.

Write an algorithm and code in python for generating geometric progression of


first six number with common ration 0.5 starting from 20.

Algorithm:

1. Initialize the first term of the geometric progression a = 20.

2. Set the common ratio r = 0.5

3. Loop six times to generate the first six terms of the geometric progression.

4. For each term in the sequence, multiply the previous term by the common ratio
r to get the next term.
# Function to generate geometric progression
def generate_geometric_progression(a, r, n):
gp_sequence = [] # List to store the sequence
for i in range(n):
gp_sequence.append(a) # Append the current term to the sequence
a *= r # Update the term for the next iteration by multiplying with common ratio
return gp_sequence
# Parameters
a = 20 # First term
r = 0.5 # Common ratio
n = 6 # Number of terms to generate

# Generate and print the geometric progression


gp = generate_geometric_progression(a, r, n)
print("Geometric Progression:", gp)

You might also like