29 Sept 2022

Posted on:

28 Sept 2022

0

# Area of a circle using radius

I am trying to calculate the area of a circle using radius. See below what I get. I do not understand the meaning of my result at all ? Please kindly help explain what is going on to me.

Posted on:

28 Sept 2022

0

Hello Martin,

The `In[*]` to the left of your current code indicates that it is still running/waiting. In this case, it's because the code is waiting for you to input the radius `r`. Unless you put in that value, the code will not proceed.

Your code, on the other hand, could use a little help. I believe the code should be something like this:

``````print("Area of a circle = %.2f"%area)
``````

Running the code would result to:

The `%f` formatter can be confusing at first, even more so when you include it to another string. It may help you to assign a variable to the rounded value, then calling that variable in the print statement. Like so:

``````r = float(input("Enter the radius of the circle: "))

area = math.pi * r ** 2
rounded_area = "%.2f" %area    #This is now a string type.

print("Area of a circle = " + rounded_area)    #We use '+' to concatenate strings
``````

It took 1 more line of code, but it's definitely more readable.

Hope this helps,
Carl

Instructor
Posted on:

29 Sept 2022

0

Hi Martin and Carl!
Thanks for reaching out.

@: Carl
Thanks for sharing this piece of information with the Community!

@: Martin
Carl explained it very well. The kernel is busy. You should obtain a number in the square brackets.

Hope this helps.
Best,
Tsvetelin