Nearest Square Function with Python -


i have sample quiz question not sure how approach while loops.

implement nearest_square function. function takes integer argument limit, , returns largest square number less limit.

a square number product of integer multiplied itself, example 36 square number because equals 6*6.

there's more 1 way write code, suggest use while loop!

here test case can copy test code. feel free write additional tests too!

test1 = nearest_square(40) print("expected result: 36, actual result: {}".format(test1)) 

i have managed solve it. thank you. def nearest_square(limit): limit = limit ** (0.5) y = int (limit) while y < limit : y = y*y return y

test1 = nearest_square(40) print("expected result: 36,actual result:{}".format(test1))

this how did while loop:

def nearest_square(value):     = 2     while < value:         square = i*i         if square == value:             return square         i+=1         value-=1  print (nearest_square(40)) 

Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -