0
假设我的句点是NOV-2016
和MAR-2018
,我需要打印所有句号,如(NOV-2016, DEC-2016, JAN-2017
直到MAR-2018)
。可以做些什么来获得理想的结果。现在我这样做,但我没有得到期望的结果:在Python中的两个句点之间打印所有句号
start_period = 'NOV-2017'
end_period = 'JUN-2019'
array = ['JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC']
year1 = int(start_period.split('-')[1])
year2 = int(end_period.split('-')[1])
diff = year2-year1
month_start = start_period.split('-')[0]
month_end = end_period.split('-')[0]
index1 = array.index(month_start)
index2 = array.index(month_end)
while diff>0:
while(diff>=1 and (index2+1) != index1):
if(index1==12):
index1 = 0
print(array[index1])
index1+=1
diff-=1
if diff==0:
break
什么是你所得到的结果呢? – litelite
NOV DEC JAN FEB MAR APR MAY JUN – saurav
但我也应该从JUL再弄输出回到JUN为2018年和2019 – saurav