Write a program to construct the first 15 terms of a geometric sequence with initial term 4 and a common ratio 1/2. The output should be a python list and the number should be rounded to 5 digits after the decimal places.

Respuesta :

The program to construct the first 15 terms of a geometric sequence with initial term 4 and a common ratio 1/2 is as follows:

def geometric(a, r):

    list_of_terms = [a]

    length = 0

    n = 2

    while length < 14:

         x = round(a*pow(r, n-1), 5)

         length += 1

         n += 1

         list_of_terms.append(x)

    return list_of_terms

print(geometric(4, 0.5))

Code explanation

The code is written in python.

  • we defined a function named geometric. The function accept two parameters as a(first term) and r(common ratio).
  • we declared a variable "list_of_terms" and store the first term in it.
  • Then we initialise length to zero
  • The number of term start from 2.
  • While the length variable is less than 14, we use the geometric formula to find the terms by increasing the value of n in the loop.
  • We append the terms to list_of_terms.
  • Then return the list_of_terms.
  • Finally, we call the function with the parameters.

learn more on python here: https://brainly.com/question/26949234

Ver imagen vintechnology