我希望我的函数打印所有选项,如下所示:
year: 2017 month: 1
year: 2017 month: 2
year: 2017 month: 3
year: 2018 month: 1
year: 2018 month: 2
year: 2018 month: 3
我写了这段代码:
years = [2017, 2018]
years_index = 0
month = 1
def parse():
global years
global years_index
global month
print(str('year: ' + str(years[years_index])) + ' month: ' + str(month))
if years_index < len(years) -1:
if month < 3:
month +=1
parse()
else:
years_index +=1
month = 1
parse()
parse()
我的代码打印这个:
year: 2017 month: 1
year: 2017 month: 2
year: 2017 month: 3
year: 2018 month: 1
我做错了什么?
月关宝盒
Cats萌萌
一只名叫tom的猫
相关分类