Hi, for my school homework we are supposed to make a for loop of the fibonacci sequence. The sequence is supposed to stop at the 10th index in the sequence. Here's my code so far;
n = 10
#// BEGIN_TODO [Fibonacci_number] Fibonacci number
fibonacci: int = 1
for i in range(fibonacci):
next_number1 = (i - 1)
next_number2 = (i - 2)
fibonacci = next_number1+next_number2
print("the fibonacci number in position " + str(i) + " corresponds to " + str(fibonacci) + ".")
if i == 11:
break
#// END_TODO [Fibonacci_number]
The output:
the fibonacci number in position 0 corresponds to -3.
the fibonacci number in position 1 corresponds to -1.
the fibonacci number in position 2 corresponds to 1.
the fibonacci number in position 3 corresponds to 3.
the fibonacci number in position 4 corresponds to 5.
the fibonacci number in position 5 corresponds to 7.
the fibonacci number in position 6 corresponds to 9.
the fibonacci number in position 7 corresponds to 11.
the fibonacci number in position 8 corresponds to 13.
the fibonacci number in position 9 corresponds to 15.
Please just tell me what's exactly going on and why it outputs this way. Don't give me any raw code as that's against the school's rules. Thank you.