- 1 year ago
How to tribonacci series value pass in array then print any index value which i want?
Comment
1 / 1
To generate a Tribonacci series and store its values in an array in Python, you can follow these steps:
- Define a function to generate the Tribonacci series and store it in an array.
- Access the desired index value from the array.
Here's a Python code example:
pythondef generate_tribonacci(n):
tribonacci_array = [0] * n
tribonacci_array[0] = 0
tribonacci_array[1] = 1
tribonacci_array[2] = 1
for i in range(3, n):
tribonacci_array[i] = tribonacci_array[i-1] + tribonacci_array[i-2] + tribonacci_array[i-3]
return tribonacci_array
# Example usage:
n = 10 # The number of elements in the Tribonacci series
index_to_print = 6 # The index of the value you want to print
tribonacci_series = generate_tribonacci(n)
print("Tribonacci series:", tribonacci_series)
print(f"Value at index {index_to_print}: {tribonacci_series[index_to_print]}")
In this example, we define the function generate_tribonacci(n)
to generate the first n
elements of the Tribonacci series and store them in the tribonacci_array
. We then access and print the value at the specified index index_to_print
.
Just replace the values of n
and index_to_print
with your desired values to get the Tribonacci series and the value at the index you want.