Perfect Squares in a Range
You are given two given numbers, A and B where 1 <= A <= B, Write a program to find the number of perfect squares in the range A to B (including A and B).
Input
The first line of input is an integer A. The second line of input is an integer B.
Explanation
In the given example,
A = 9 and B = 100. The perfect squares in the range A to B are
3 * 3 = 9
4 * 4 = 16
5 * 5 = 25
6 * 6 = 36
7 * 7 = 49
8 * 8 = 64
9 * 9 = 81
10 * 10 = 100
So, the output should be
8.
Sample Input 1
9
100
Sample Output 1
8
Sample Input 2
625
1444
Sample Output 2
14
import math
list2 = []
A = int(input('Enter first number here:'))
B = int(input('Enter second number here: '))
for i in range(A, B+1):
j = math.sqrt(i)
if j.is_integer() is True:
list2.append(i)
print(len(list2))
Enter first number here:9
Enter second number here: 100
8
Enter first number here:625
Enter second number here: 1444
14
Comments
Leave a comment