[英]Make Recursive Function Return a Tuple
I want the following function to return a tuple for every year ie. 我希望下面的函数每年返回一个元组。 if its 5 years it will give me a tuple of year1, year2, year3, year4, year5.
如果它的5年,它将给我元组Year1,year2,year3,year4,year5。
def nextSalaryFixed(salary, percentage, growth, years):
if years == 1:
tup = (salary * (percentage * 0.01), )
return tup[years-1]
else:
tup = (nextEggFixed(salary, percentage, growth, years - 1) * ((1 + (0.01 * growth))) + (salary * (percentage * 0.01)))
print(tup)
return tup
result = []
def nextSalaryFixed(salary, percentage, growth, years):
if years == 1:
tup = salary * (percentage * 0.01)
else:
tup = (nextSalaryFixed(salary, percentage, growth, years - 1) *
((1 + (0.01 * growth))) + (salary * (percentage * 0.01)))
result.append((years, tup))
return tup
nextSalaryFixed(10000, 10, 5, 5)
result # [(1, 1000.0), (2, 2050.0), (3, 3152.5), (4, 4310.125), (5, 5525.63125)]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.