Problem 4 (100pts)
实现swine_swap。如果由于Swine Swap规则导致两名玩家的得分互换,它接受结果得分并返回True。
在编写任何代码之前,请解锁测试以验证您对问题的理解。
python ok -q 04 -u
解锁完成后,开始实现您的解决方案。您可以使用以下命令检查正确性:
python ok -q 04
Solutions
def swine_swap(score):
"""Return whether the players' scores will be swapped due to Swine Swap.
score: The total score of the current player.
Hint: for this problem, you will find the math function sqrt (i.e., square root) useful.
>>> sqrt(9)
3.0
>>> floor(sqrt(9))
3
>>> floor(sqrt(8))
2
"""
# BEGIN PROBLEM 4
return floor(sqrt(score)) ** 2 == score
# END PROBLEM 4