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

Answer :

MrRoyal

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=' ')

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=' ')

Other Questions