Python Modules
💡
Exercise 40

Solar System 15 XP Easy

Ctrl+Enter Run Ctrl+S Save

The math module has useful constants and functions:

import math print(math.pi) # 3.141592653589793 print(math.sqrt(144)) # 12.0 print(math.floor(3.7))# 3 print(math.ceil(3.2)) # 4

You can import specific items:

from math import pi, sqrt print(pi) # No need for math.pi
📋 Instructions
Use the `math` module to calculate the surface area and volume of planets! Formulas for a sphere: - Surface area: $4\pi r^2$ - Volume: $\frac{4}{3}\pi r^3$ Earth's radius is `6371` km. Calculate and print: ``` Earth's surface area: 510064471.91 sq km Earth's volume: 1083206916845.75 cu km ``` Round to 2 decimal places.
surface_area = 4 * math.pi * earth_radius ** 2. volume = (4/3) * math.pi * earth_radius ** 3.
⚠️ Try solving it yourself first — you'll learn more!
import math

print(math.pi)        # 3.141592653589793
print(math.sqrt(144)) # 12.0
print(math.floor(3.7))# 3
print(math.ceil(3.2)) # 4
🧪 Test Cases
Input
Run your code
Expected
Earth's surface area: 510064471.91 sq km Earth's volume: 1083206916845.75 cu km
Expected program output
main.py
Hi! I'm Rex 👋
Output
Ready. Press ▶ Run or Ctrl+Enter.