229k views
0 votes
Write a program that prompts the user to enter two positive integers a and b with a < b and then prints the list of all the perfect squares that are between a and b, inclusive

User Zyy
by
6.3k points

1 Answer

0 votes

Answer:

Written in Python

import math

a = int(input("a: "))

b = int(input("b: "))

for i in range(a,b+1):

sqqrt = math.sqrt(i)

if int(sqqrt + 0.5) ** 2 == i:

print(i,end=' ')

Step-by-step explanation:

This line import math library

import math

This line prompts user for user input (a)

a = int(input("a: "))

This line prompts user for user input (b)

b = int(input("b: "))

This iterates from a to b (inclusive)

for i in range(a,b+1):

This checks for perfect square

sqqrt = math.sqrt(i)

if int(sqqrt + 0.5) ** 2 == i:

This prints the number if it is a perfect square

print(i,end=' ')

User Norbert Szenasi
by
6.1k points