python函数中默认参数的补充
题目:糖果平均分,为了公平起见,剩余的糖果需销毁;如果没有特别设定,默认平均分给3个人。
代码如下:
def to_smash(total_candies, number_of_friends = 3):
"""Return the number of leftover candies that must be smashed after distributing the given number of candies evenly between the number of friends.
>>> to_smash(91,4)
3
"""
return total_candies % number_of_friends
output:
to_smash(91)
1
to_smash(91,4)
3