Re: [问题] 循环问题

楼主: lycantrope (阿宽)   2022-02-21 15:47:05
# 输入资料
input_date = input('Please input date range(ex: 2018/6~2019/12): ')
# 解析资料
start_date, end_date = input_date.split('~')
start_year, start_month = [int(i) for i in start_date.split('/')]
end_year, end_month = [int(i) for i in end_date.split('/')]
total_month = 12*(end_year - start_year)+ 1+ end_month - start_month
for month in range(total_month):
Y = start_year + (start_month+month-1) // 12
M = 1 + (start_month + month -1) % 12
print(f"{Y}/{M}")
作者: TuCH (谬客)   2022-02-21 16:46:00
Good!
作者: skyleona (多益爆了!)   2022-02-21 19:35:00
感谢ly大解答

Links booklink

Contact Us: admin [ a t ] ucptt.com