How to Find the Area of Circle in Python

In this tutorial, we will program 'How to Find the Area of a Circle in Python.' We will learn how to calculate and determine the actual area of a circle. The objective is to automatically find the area of a circle based on the number provided. I will provide a sample program to demonstrate the actual coding process in this tutorial.

This topic is very easy to understand. Just follow the instructions I provide, and you will be able to do it yourself with ease. The program I will show you covers the basics of programming for calculating the area of circle. I will do my best to provide you with a simple method for finding the actual area of circle. So, let's start with the coding.

Getting Started:

First you will have to download & install the Python IDLE's, here's the link for the Integrated Development And Learning Environment for Python https://www.python.org/downloads/.

Creating Main Function

This is the main function of the application. The following code will display a simple GUI in terminal console that will display program. To do this, simply copy and paste these blocks of code into the IDLE text editor.
  1. import math
  2.  
  3. def area(r):
  4.   area = math.pi* pow(r,2)
  5.   return print('Area of circle is:' ,area)
  6.  
  7. ret = False
  8.  
  9.  
  10. while True:
  11.   print("\n================= Find the Area of Circle =================\n\n")
  12.  
  13.  
  14.   num=int(input("Enter a number: "))
  15.  
  16.   area(4)
  17.  
  18.   opt = input("\nDo you want to try again?(yes/no): ")
  19.  
  20.   if opt.lower() == 'yes':
  21.     ret=False
  22.   elif opt.lower() == 'no':
  23.     ret=True
  24.     print("Exiting program....")
  25.  
  26.   else:
  27.     print("Please enter yes/no:")
  28.     break
  29.  
  30.   if ret == False:
  31.     continue

This Python script calculates the area of a circle with a fixed radius of 4. It repeatedly prompts the user to input a number (though the input is not used in the calculation) and then calculates and displays the area. The user is asked whether they want to try again, and the loop continues until the user chooses to exit.

Output:

There you have it we successfully created How to Find the Area of Circle in Python. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!

More Tutorials for Python Language

Python Tutorials

Add new comment