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
-
print all the perfect square number between 1 and 500 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:
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.
For that you need to enter the number as 500 when prompted - please enter the range till program runs.
So instead of entering 133, please enter 500 and you can see the output of print all the perfect square number between 1 and 500 in python.
Thank you for reading this article on perfect squares in the given range in python. Please share, if you find this article helpful to you.👍👍👍👍
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 06,2024