First a typo: "But the answer is 49
, which means 7*7"
Quote:I'm trying to compute the nearest square of a number less than a limit using python.
If limit is 36, which answer do you expect 25 or 36 ?
Quote:It works, the output answer is 36. But I'm still a little bit confused about the condition needed.
You loop until condition is wrong, and it turn wrong when
is 1 step too far
You could have done it that way:
limit = 40
num = 0
while num**2 < limit:
num += 1
nearest_square = (num-1)**2