Python Nozioni di baseFacile

Fattoriale di un numero

Guida dettagliata e implementazione Python per il problema "Fattoreriale di un numero".

Dichiarazione del problema

Facile

Scrivi una funzione factorial(n) che accetta un intero non negativo n e restituisce il suo fattoriale. Il fattoriale di n (scritto come n!) è il prodotto 1 × 2 × 3 × ... × n. Per definizione, 0! = 1.

Vincoli
  • 0 <= n <= 20

Esempi

Example 1
Input
n = 5
Output
120
Explanation

5! = 1 × 2 × 3 × 4 × 5 = 120.

Example 2
Input
n = 0
Output
1
Explanation

0! is defined as 1.

Example 3
Input
n = 10
Output
3628800
Explanation

10! = 3628800.

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.