28 lines
858 B
Python
28 lines
858 B
Python
"""
|
|
1. Napisz rekurencyjną funkcję, która zwróci n-ty wyraz ciągu Fibonacciego.
|
|
2. Napisz funkcję, która obliczy n-ty wyroz ciągu Fibonacciego nie korzystając z rekurencji.
|
|
Np. możesz wykorzystać listę do obliczania kolejnych wartości ciągu.
|
|
|
|
Ciąg Fibonacciego:
|
|
a[0] = 1, a[1] = 1, a[n] = a[n-1] + a[n-2] dla n>=2
|
|
|
|
"""
|
|
|
|
def fibonacciValue(limit, currentValue=1, previousValue=1):
|
|
if currentValue < limit:
|
|
print(currentValue)
|
|
fibonacciValue(limit, currentValue + previousValue, currentValue)
|
|
else:
|
|
return
|
|
|
|
def fibonacciSteps(stepLimit, currentValue = 1, previousValue = 1, step = 0):
|
|
if step < stepLimit:
|
|
print(currentValue)
|
|
step += 1
|
|
fibonacciSteps(stepLimit, currentValue + previousValue, currentValue, step)
|
|
else:
|
|
return
|
|
|
|
fibonacciValue(100)
|
|
|
|
fibonacciSteps(10) |