Computer Science, asked by pratiktelekune1115, 8 months ago

Write a python program that accepts radius of a circle and prints its area and circumference

Answers

Answered by Snehpriyanshu
18

Explanation:

  • from math import pi.
  • r = float(input ("Input the radius of the circle : "))
  • print ("The area of the circle with radius " + str(r) + " is: " + str(pi * r**2)
Answered by mahinderjeetkaur878
0

Python program:

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

# Calculate the area of the circle

area = math.pi * radius ** 2

# Calculate the circumference of the circle

circumference = 2 * math.pi * radius

# Print the results

print(f"The area of the circle is: {area:.2f}")

print(f"The circumference of the circle is: {circumference:.2f}")

Explanation of the Python program that accepts the radius of a circle and prints its area and circumference:

  • Here, we first import the math module so that we can use the value of pi in our program.
  • We then prompt the user to enter the radius of the circle, and use the float() function to convert the user input to a floating-point number.
  • We calculate the area of the circle using the formula pi * r^2, where pi is the mathematical constant and r is the radius of the circle.
  • We use the math.pi constant provided by the math module to get the value of pi.
  • We calculate the circumference of the circle using the formula 2 * pi * r, where pi is the mathematical constant and r is the radius of the circle.
  • Finally, we use the print() function to output the results to the user. We use f-strings to format the output and include the values of the area and circumference in the output string.
  • We also use the :.2f format specifier to round the output to 2 decimal places, which is common for measurements involving circles.

To know more: -

https://brainly.in/question/7435106?referrer=searchResults

https://brainly.in/question/32604791?referrer=searchResults

#SPJ3

Similar questions