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)