[問題] 迴圈

看板Python作者 (:))時間4年前 (2019/08/14 03:04), 4年前編輯推噓4(402)
留言6則, 6人參與, 4年前最新討論串1/1
Hi 大家好 有一個迴圈的問題想請問大家 該怎麼寫 while 迴圈 這以下的code 只 run 10次呢? 目前鬼打牆 一直寫不出來 ... def GoNextPage(old_url): GetNext20Records("Next 20 Records") url = browser.current_url if old_url == url: return html = GetHtml(url) url_lst = GetUrl(html) for url in url_lst[:]: url = root_url + url url = url.replace(' ', '%20') GetFile(url) GoNextPage(url) 先謝謝大家了!! 再次感謝大家的幫忙,修改一點P大的code使我整個程式可以run, 在這邊分享: def GoNextPage(number_of_pages): if number_of_pages > 0: GetNext20Records("Next 20 Records") url = browser.current_url html = GetHtml(url) url_lst = GetUrl(html) for url in url_lst[:]: url = root_url + url url = url.replace(' ', '%20') GetFile(url) GoNextPage(number_of_pages-1) else: return #running pages number_of_pages = 4 GoNextPage(number_of_pages) -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 204.40.130.131 (加拿大) ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1565723071.A.482.html

08/14 06:39, 4年前 , 1F
你是在問迴圈還是遞迴?
08/14 06:39, 1F

08/14 08:35, 4年前 , 2F
為甚麼一定要用while 簡單點a=0;a+=1;if a==10:break
08/14 08:35, 2F

08/14 09:20, 4年前 , 3F

08/14 09:34, 4年前 , 4F
While在哪?
08/14 09:34, 4F

08/14 10:35, 4年前 , 5F
謝謝 S大、P大,我來試一下 :)
08/14 10:35, 5F

08/14 10:37, 4年前 , 6F
是recursive改iterative的意思麼?
08/14 10:37, 6F
※ 編輯: ibgvdlbj (204.40.194.132 加拿大), 08/14/2019 20:28:32 ※ 編輯: ibgvdlbj (204.40.194.132 加拿大), 08/14/2019 23:17:59 ※ 編輯: ibgvdlbj (204.40.194.132 加拿大), 08/14/2019 23:19:51
文章代碼(AID): #1TKmc_I2 (Python)