实现函数subtract_months
从给定的年和月减去n
个月数
输入:是元组的列表[(year1, month1, months_to_subtract1), (year2, month2, months_to_subtract2), ...]
其中,年是一个4位整数
月是介于1到12之间的整数值,1=一月,2=二月。。。12(12月)和
月到月是一个整数
输出:是元组的列表[(result_year1, result_month1), (result_year2, result_month2), ...]
年(4位整数)月(1到12之间的整数值,1=一月,2=二月,…12=十二月)
例如:从2020年5月起减去3个月。这将导致2020年2月的产出 在本例中,输入:年=2020月=5 产量:年=2020月=2
def subtract_months(input_list):
output_list = []
#TODO: implement your code here
return output_list
我提出的解决方案,适用于所有情况
def减去月份(年、月、月减去):
减去月数(2010,5,7)
虽然Shubham的逻辑是正确的,但我想改进它,因为输入是一个元组列表,输出也是一个元组列表。因此,我们将给出一个元组列表作为参数,然后对元组和列表进行迭代,而不是对函数的3个参数进行硬编码。此外,这应该返回一个元组列表
相关问题 更多 >
编程相关推荐