Python: Input the radius of a circle and compute the area
Python Basic: Exercise-4 with Solution
Write a Python program which accepts the radius of a circle from the user and compute the area.
Python: Area of a Circle
In geometry, the area enclosed by a circle of radius r is πr2. Here the Greek letter π represents a constant, approximately equal to 3.14159, which is equal to the ratio of the circumference of any circle to its diameter.
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))
Input the radius of the circle : 1.1 The area of the circle with radius 1.1 is: 3.8013271108436504
Visualize Python code execution:
The following tool visualize what the computer is doing step-by-step as it executes the said program:
Python Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a Python program to display the current date and time.
Next: Write a Python program which accepts the user's first and last name and print them in reverse order with a space between them.
What is the difficulty level of this exercise?
Test your Python skills with w3resource's quiz
Python: Tips of the Day
try: foo() except Exception: print("Exception occured") else: print("Exception didnt occur") finally: print("Always gets here")
- New Content published on w3resource:
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework