Write a function to represent the geometric sequence 6, 18, 54…..

1 answer

To represent a geometric sequence, we can use a function that describes the \( n \)-th term of the sequence. In this case, the sequence you provided is 6, 18, 54, ...

To determine the parameters of the geometric sequence:

  • The first term \( a \) is 6.
  • The common ratio \( r \) can be found by dividing the second term by the first term: \( r = \frac{18}{6} = 3 \).

The general formula for the \( n \)-th term of a geometric sequence can be written as:

\[ a_n = a \cdot r^{(n-1)} \]

where \( a \) is the first term and \( r \) is the common ratio.

Now, we can write this as a Python function:

def geometric_sequence(n):
    a = 6  # First term
    r = 3  # Common ratio
    return a * (r ** (n - 1))

# Example usage
for i in range(1, 6):  # Get the first 5 terms
    print(geometric_sequence(i))

This function, geometric_sequence(n), returns the \( n \)-th term of the geometric sequence defined by the first term 6 and a common ratio of 3. The example usage will print the first five terms of the sequence.