Python Nozioni di baseFacile

Serie di Fibonacci fino all'ennesimo termine

Guida dettagliata e implementazione Python per il problema "Serie di Fibonacci fino all'ennesimo termine".

Dichiarazione del problema

Facile

Scrivi una funzione fibonacci_series(n) che accetta un intero non negativo n e restituisce un elenco contenente i primi n termini della serie di Fibonacci. La serie di Fibonacci inizia con 0 e 1, e ogni termine successivo è la somma dei due termini precedenti. Se n è 0, restituisce una lista vuota.

Vincoli
  • 0 <= n <= 50

Esempi

Example 1
Input
n = 6
Output
[0, 1, 1, 2, 3, 5]
Explanation

The first 6 Fibonacci terms: 0, 1, 1 (0+1), 2 (1+1), 3 (1+2), 5 (2+3).

Example 2
Input
n = 1
Output
[0]
Explanation

The first 1 term of the Fibonacci series is just [0].

Example 3
Input
n = 0
Output
[]
Explanation

With n=0, there are no terms to return.

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.