Re: [問題] 迴圈問題

看板Python作者 (阿寬)時間2年前 (2022/02/21 15:47), 編輯推噓1(101)
留言2則, 2人參與, 2年前最新討論串3/7 (看更多)
# 輸入資料 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}") -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 217.178.38.4 (日本) ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1645429629.A.2C5.html

02/21 16:46, 2年前 , 1F
Good!
02/21 16:46, 1F

02/21 19:35, 2年前 , 2F
感謝ly大解答
02/21 19:35, 2F
文章代碼(AID): #1Y4qDzB5 (Python)
文章代碼(AID): #1Y4qDzB5 (Python)