write a program in Python enter the radius and calculate the perimeter of the circle
Answers
Hey there!!
To do this, we will need to know the formula for the perimeter of the circle
The formula : 2π2.
π has many digits, we can not enter it on python. There are two ways, one, use 22/7 or import pi from math
It will give us the same number.
First method:
radius = float(input('Enter the radius:'))
print('The perimeter of the circle is:', (2)*(22/7)*(radius))
Second method:
from math import pi
radius = float(input('Enter the radius of the circle:'))
print('The perimeter of the circle is:',2*pi*radius)
Hope my answer helps! :)
The following codes will have to be typed in script mode, save and then executed.
CODE 1:
r = float(input("Enter the radius of the circle:"))
print("The perimter of the circle is", 2*3.14*r)
OUTPUT:
5
CODE 2:
r = float("Enter the radius of the circle:"))
pm = 2*3.14*r
print("The perimeter of the circle is", pm)
OUTPUT:
5
Here, the float() function has been used in order to accept whatever value [fractional/integer], to be calculated. The int() function may be used as well though calculation will not take place if a decimal value has been entered when asked for input.