所以我的问题是我一直在努力解决一个学习 Python 的问题(它说它是为初学者准备的,我已经完成了它,但由于某种原因和计算,我在返回函数方面苦苦挣扎)。
我需要使find_monthly_savings
函数采用金额和年数函数来计算用户需要"每月"保存的金额,如果amount is < 0
那么return None
,或者如果years <= 0
那么return None
。
def find_monthly_savings(amount, years): # used to divide the amount by years
return amount / years
def amount(number):
if number < 0:
return None
def years (months):
if years < 0:
return None
find_monthly_savings(amount = 360, years = 1) #calling upon the dms function
你来了:
def find_monthly_savings(amount, years): # used to divide amount by years
if amount < 0:
return None
if years <= 0:
return None
return amount / years