内容:
Your classmates asked you to copy some paperwork for them.
You know that there are 'n' classmates and the paperwork has 'm' pages.
Your task is to calculate how many blank pages do you need.
Example:
paperwork(5, 5) == 25
Note: if n < 0 or m < 0 return 0!
解决方案:python
方法一:
(1)
def paperwork(n, m):
if (n<0 or m<0):
return 0
else :
return n*m
(2)
def paperwork(n, m):
if m > 0 and n > 0:
return m*n
else:
return 0
方法二:
def paperwork(n, m):
return max(n, 0)*max(m, 0)
方法三:
paperwork = lambda m,n: m*n if m>0 and n>0 else 0
方法四:
def paperwork(n, m):
return n*m if n>=0 and m>=0 else 0

本文介绍了一种计算方法,用于确定为多个同学复印特定页数作业所需的总空白页数。通过四种不同的Python函数实现,确保了当输入的班级人数或作业页数为负数时,返回值为零。
3129

被折叠的 条评论
为什么被折叠?



