Import package
Let's say you wanted to calculate the circumference and area of a circle. Here's what those formulas look like:
$$C = 2 \pi r$$ $$A = \pi r^2 $$
Rather than typing the number for pi, you can use the math package that contains the number
For reference, ** is the symbol for exponentiation. For example 3**4 is 3 to the power of 4 and will give 81.
This exercise is part of the course
Introduction to Python
Exercise instructions
- Import the
mathpackage. - Use
math.pito calculate the circumference of the circle and store it inC. - Use
math.pito calculate the area of the circle and store it inA.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Import the math package
import ____
# Calculate C
C = 2 * 0.43 * ____
# Calculate A
A = ____ * 0.43 ** 2
print("Circumference: " + str(C))
print("Area: " + str(A))