Python Nozioni di baseFacile

Calcola l'area di un cerchio

Guida dettagliata e implementazione Python per il problema 'Calcola l'area di un cerchio'.

Dichiarazione del problema

Facile

Scrivi una funzione area_of_circle(radius) che accetta un numero non negativo radius e restituisce l'area di un cerchio con quel raggio, arrotondata a 2 cifre decimali.

Usa la formula: Area = π × raggio². Utilizza math.pi o 3.14159265358979 per π.

Vincoli
  • 0 <= radius <= 10^4

Esempi

Example 1
Input
area_of_circle(5)
Output
78.54
Explanation

Area = π × 5² = π × 25 = 78.5398... ≈ 78.54.

Example 2
Input
area_of_circle(1)
Output
3.14
Explanation

Area = π × 1² = π ≈ 3.14.

Example 3
Input
area_of_circle(7)
Output
153.94
Explanation

Area = π × 7² = π × 49 = 153.938... ≈ 153.94.

Need a Hint?
Prendi in considerazione l'utilizzo di strutture dati specifiche di Numbers 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.