How to Find Area and Perimeter of a Circle in Python


1. Introduction

In this example, we will see how to calculate the area and perimeter of a circle in Python.
To calculate the perimeter and area of a circle, you need to use the value of a constant π.  Math module in Python contains this constant.

Source Code

#! /usr/bin/env python3
# -*- coding: utf-8 -*-
import math

radius = float(input("Please input radius of cricle:"))
circumference = 2*math.pi*radius
area = math.pi*radius*radius
print ("Circumference of circle: %.2f" % circumference)
print ("Area of cricle: %.2f"% area)

4. Results

Please input radius of cricle: 3
Circumference of circle: 18.85
Area of cricle: 28.27

Please input radius of cricle: 1
Circumference of circle: 6.28
Area of cricle: 3.14
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
Advertisement