How to make a python program to calculate area of circle when radius should be input of user | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to make a python program to calculate area of circle when radius should be input of user

12th Jul 2019, 6:52 PM
Astaturini M3
Astaturini M3 - avatar
9 Answers
+ 5
This a really simple task. use input(...) to get the radius as int from user. The formula for the calculation is: area = (math.pi * (radius**2)) To use the pi constant you have to import math in the top of your code.
12th Jul 2019, 7:02 PM
Lothar
Lothar - avatar
+ 3
Astaturini M3 What's the code that you're having trouble with?
12th Jul 2019, 7:49 PM
Faisal
Faisal - avatar
+ 1
Rather than surrounding r**2 in the int() function, I would recommend instead surrounding input() in it as to allow for whatever input the user enters automatically be interpreted as an integer. As for pi, rather than using 22/7, you could just import the math module and use the math.pi function as that will return a more accurate value of the number
12th Jul 2019, 8:01 PM
Faisal
Faisal - avatar
+ 1
All you would need to do is just replace input() with int(input()) and you should be good for that 👍
12th Jul 2019, 8:04 PM
Faisal
Faisal - avatar
+ 1
r=int(input()) pi=22/7 print(pi*r**2)
26th Jul 2019, 9:05 AM
Iqbal Khan
Iqbal Khan - avatar
0
I am trying but it is not working
12th Jul 2019, 7:09 PM
Astaturini M3
Astaturini M3 - avatar
0
r = input() pi = 22/7 print(int(r**2)*pi)
12th Jul 2019, 7:59 PM
Astaturini M3
Astaturini M3 - avatar
0
How to make an input to be integer
12th Jul 2019, 8:03 PM
Astaturini M3
Astaturini M3 - avatar
0
Thanks master
12th Jul 2019, 8:05 PM
Astaturini M3
Astaturini M3 - avatar