If you have any query feel free to chat us!
Happy Coding! Happy Learning!
In a geometric progression (GP), each term is obtained by multiplying the previous term by a constant ratio (r). The nth term of a geometric progression can be calculated using the formula:
nth term (Tn) = a * r^(n-1)
where:
- Tn is the nth term of the GP,
- a is the first term of the GP, and
- r is the common ratio between consecutive terms.
To calculate the nth term of a geometric progression in Python, you can define a function that takes the first term (a), common ratio (r), and the value of n as input parameters and returns the nth term using the formula mentioned above.
Here's a Python function to calculate the nth term of a geometric progression:
pythonCopy code
def nth_term_geometric_progression(a, r, n): return a * (r ** (n - 1)) # Example usage: first_term = 2 common_ratio = 3 n_value = 5 nth_term = nth_term_geometric_progression(first_term, common_ratio, n_value) print(f"The {n_value}th term of the geometric progression is: {nth_term}")
In this example, we have a first term
first_term
with a value of 2, a common ratiocommon_ratio
with a value of 3, and we want to find the 5th termn_value
of the geometric progression. Thenth_term_geometric_progression
function is used to calculate the nth term, which is then printed to the console.
Comments: 0