Hoppy discovers a massive library deep in the fortress. The shelves are filled with "Scrolls" (Modules).
Why write a spell from scratch when an ancient wizard has already perfected it?
The import Spell
To use a scroll from the library, you must import it first. Then you can use its powers by saying scroll_name.spell_name.
import math print(math.pi) # 3.14159... print(math.sqrt(16)) # Square root: 4.0
1
Import math
At the top of your code, type import math.
2
Use the power of Pi
The formula for a circle's area is $\pi r^2$.
Change area = 0 to use math.pi * radius * radius.
There are thousands of scrolls (modules) in the Python library. math, random, time, json... unlimited power!
Suggested SolutionExpandCollapse
ExpandCollapse
Solution:
import math # Step 1: Import the scroll
radius = 5
# Step 2: Use the formula pi * r^2
area = math.pi * radius * radius
print("Area of the circle: " + str(area))Advanced TipsWant more? Click to expandClick to collapse
F. Standard Library
- Python comes with "batteries included". This means you get tons of powerful modules (scrolls) for free instantly.
- You don't need to download
math, it's already there waiting for you.
Loading...
Terminal
Terminal
Ready to run...