Ngibhalele umsebenzi wokuphindaphinda wokubala inombolo ka-nth kaFibonacci
Ngezansi kunomsebenzi we-Python obonakalayo fib ((n) obala inombolo ye-nth ye-Fibonacci. Lokhu kuhlukaniswe kwaba yicala eliyisisekelo necala eliphindaphindwayo. Icala eliyisisekelo linikezwa iqiniso lokuthi imigomo emibili yokuqala yokulandelana kukaFibonacci ingu-0 no-1, ngakho-ke i-fib(0) = 0 ne-fib(1) = 1. Icala eliphindaphindwayo linikezwa iqiniso lokuthi inombolo ye-nth yeFibonacci f_n ingabhalwa njengenani lezinombolo ezimbili zangaphambilini zeFibonacci, ngakho-ke f_n = f_{n-1} + f_{n-2}. Uma sihlanganisa konke lokhu, sithola  ` ` ` ` def fib ((n): # isisekelo uma n == 0: 0 ukubuyisa uma n == 1: ukubuyisa 1  # icala eliphindayo ukubuyisa i-fib ((n - 1) + i-fib ((n - 2) ` ` ` `  Lokhu kuzokwenza ukubala ngokunembile inombolo ye-nth ye-Fibonacci yezinombolo ezingezona ezingezinhle n. Nokho, ukubala izinombolo zikaFibonacci ngale ndlela kuthatha isikhathi esiphezulu kunani lika-n, ngakho-ke le khodi ingase ihambe kancane kakhulu ekufakweni okukhulu. Kungase kuthuthukiswe ngokufunda ngekhanda imiphumela yangaphambilini, noma ngokusebenzisa indlela engaphindeki. Izindlela ezilula zokuphindaphinda zingaxazulula inkinga ngokushesha, futhi kunezinkulumo ezivaliwe zenombolo ye-nth yeFibonacci futhi ziyashesha ukuhlola.