Python - Check if a number is a square
问题 I wrote a function that returns whether a number input is a square or not def is_square(n): if n<1: return False else: for i in range(int(n/2)+1): if (i*i)==n: return True else: return False I am confident that this code works. But when I did the test cases, example: test.expect( is_square( 4)) , it says that the value is not what was expected. 回答1: Your function doesn't actually work, as it will immediatley return False on the first non-square-root found. Instead you will want to modify your