Articles

Python program to print all the perfect square number in the given range

Python program to print all the perfect square number in the given range


In this python program guide, we will learn:

  • perfect squares in the given range in python

πŸ€·β€β™€οΈπŸ€·β€β™€οΈWhat do you mean by perfect square number ?

 

A number is said to be a perfect square number if it can be obtained by the multiplication of two equal integer numbers.

 

for example,

16 is a perfect square number because it can be obtained by the multiplication of two equal integers (4*4=16).

 

our task is to find all the perfect squares number in the given range by the user.

 

So let’s start to find the solution to this tricky problem.

 

πŸ“™πŸ“™ Print perfect square numbers in python in range

 

Code to print perfect square numbers in python is given below:

 

# perfect square number in the given range
i=1
t=int(input("please enter the range till program runs "))
for j in range(1,t+1):   # range from 1 to t
    while(i<=((j//2)+1)):
        if(i**2==j):
            print(j)
        i+=1    
    i=1

πŸ‘‰πŸ‘‰the program will print the perfect square number in the given range as inputted by the user.

 

πŸ€·β€β™€οΈπŸ€·β€β™€οΈπŸ€·β€β™€οΈOutput to the above program in python is given below:

please enter the range till program runs 133
1
4
9
16
25
36
49
64
81
100
121

Our program prints the perfect square number from 1 to the given range.  

 

πŸ“–πŸŽ―Screenshot of running  program in jupyter notebook:

 

print perfect square numbers in python

 

As we can see our program prints the perfect square numbers in the given range. So,our program has been run successfully.

 

Similarly, we can print all the perfect square number between 1 and 500 in python or any range.

 

Thank you for reading this article. Please share, if you find this article helpful to you.πŸ‘πŸ‘πŸ‘πŸ‘

 

Basic Python Programs

Would you like to see your article here on tutorialsinhand. Join Write4Us program by tutorialsinhand.com

About the Author
Ayush Bajpai
I am a data science enthusiast. I love to learn new technology πŸ› πŸ› .you can reach me at this url www.linkedin.com/in/ayushbajpai47
Page Views :    Published Date : May 10,2021  
Please Share this page

Related Articles

Like every other website we use cookies. By using our site you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service. Learn more Got it!