Python Nozioni di baseFacile

Potenza di un numero

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

Dichiarazione del problema

Facile

Scrivi una funzione power(base, exp) che accetta due interi non negativi base e exp e restituisce base elevato alla potenza exp (ovvero, base^exp). Si noti che qualsiasi numero elevato a 0 è 1.

Vincoli
  • 0 <= base <= 100
  • 0 <= exp <= 20

Esempi

Example 1
Input
base = 2, exp = 10
Output
1024
Explanation

2^10 = 1024.

Example 2
Input
base = 5, exp = 0
Output
1
Explanation

Any number raised to the power 0 is 1.

Example 3
Input
base = 3, exp = 4
Output
81
Explanation

3^4 = 3 × 3 × 3 × 3 = 81.

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.