Python Nozioni di baseFacile

Trova l'ennesimo termine della serie di Fibonacci

Guida dettagliata e implementazione Python per il problema "Trova l'ennesimo termine della serie di Fibonacci".

Dichiarazione del problema

Facile

Scrivi una funzione fibonacci_nth(n) che accetta un intero positivo n e restituisce l'n-esimo termine della serie di Fibonacci (indicizzata in 1). La serie è: F(1) = 0, F(2) = 1, F(3) = 1, F(4) = 2, F(5) = 3, ...

Vincoli
  • 1 <= n <= 50

Esempi

Example 1
Input
n = 5
Output
3
Explanation

The 5th Fibonacci term is 3. The series: 0, 1, 1, 2, 3.

Example 2
Input
n = 1
Output
0
Explanation

The 1st Fibonacci term is 0.

Example 3
Input
n = 10
Output
34
Explanation

The 10th Fibonacci term is 34. The series: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34.

Need a Hint?
Prendi in considerazione l'utilizzo di strutture dati specifiche di Basics come set o heap.
Edge Cases to Watch
  • Strutture di input vuote
  • Ingressi a elemento singolo
  • Grandi limiti numerici

Pronto a risolvere?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

Apri nell'editor
Found this breakdown helpful?

PyRun is built and maintained by an independent solo developer. If this helped your interview prep, consider buying a coffee!

Buy me a coffee

Risorse Python consigliate

Espandi le tue conoscenze con tutorial interattivi, foglietti illustrativi e confronti di codici correlati.