I tried to use the “import math” in my code, but it is saying it is unused. Could anyone help me please? I am on python.
Hey @ArnavGupta113, welcome to the forums!
Yes, that is intended behavior as you have not used it yet. It is not an error, it’s a warning. You can tell because it’s orange.
I want to use pi, but even when I do it it still has an orange line under it.
Try refreshing. If you’ve used the math
library and it still says that you haven’t used it, then refreshing should fix it.
@ArnavGupta113 you have to use math.pi
if you haven’t. Alone you can’t use pi
because it is part of the module math
.
As @SalladShooter says, you need to use math.pi
instead of just pi
. There is also a typo in your raduius
variable name.
For anyone who is wondering, this is the OP’s current code:
https://replit.com/@ArnavGupta113#main.py
import math
radius = 4
area = pi * raduius # Change to math.pi * radius
Another solution would be to import pi
on its own if you do not plan to use any other math
components. This would allow you to use just pi
instead of math.pi
in your equation.
from math import pi
radius = 4
area = pi * radius
Also area of a circle should be calculated by pi*(R**2) not pi*R, keep that in mind
Order of operations?
Not sure what you mean, but exponential operations (or **
in this case) come before anything else (excluding parentheses, which are not needed in this case.) area = math.pi * radius ** 2
Brackets are optional, but the code reads better with them (for me personally).