Create a function that takes in a positive number and return 2 integers such that the number is between the squares of the 2 integers. It returns the same integer twice if the number is a square of an integer.
Answers
Answered by
0
A function that takes in a positive number and return 2 integers such that the number is between the squares of the 2 integers. It returns the same integer twice if the number is a square of an integer is likewise:
def sqApprox(num):
i = 0
minsq = 0 # set lower bound
maxsq = math.ceil(num’l’num)
# set upper bound
while i< maxsq :
# set ‘while’ termination condition
if i*i< =num and i>minsq:
# complete inequality condition
minsq = i
if i*i> =num and i<maxq
# complete inequality condition
maxsq = i
i+=l
# update i so that ‘while’ will terminate return (minsq, maxsq)
Similar questions
English,
5 months ago
Biology,
5 months ago
Computer Science,
11 months ago
Physics,
1 year ago
Physics,
1 year ago