Set num1 = 0 and num2 =1 (first two numbers of the sequence)
Run loop ten times
In each iteration
print num1 as the current number of the sequence
Add last two numbers to get the next number res = num1+ num2
update values of num1 and num2. Set num1=num2 and num2=res
Solution:
# first two numbers
num1, num2 = 0, 1
print("Fibonacci sequence:")
# run loop 10 times
for i in range(10):
# print next number of a series
print(num1, end=" ")
# add last two numbers to get next number
res = num1 + num2
# update values
num1 = num2
num2 = res
Hint:
num1 = 0
andnum2 =1
(first two numbers of the sequence)num1
as the current number of the sequenceres = num1+ num2
num1
andnum2
. Setnum1=num2
andnum2=res
Solution:
need an explanation for this answer? contact us directly to get an explanation for this answer