40923123 cp2020

  • Home
    • Site Map
    • reveal
    • blog
  • 首頁
  • 第一組組員
  • git指令表
  • HW1
    • unit 1 succeeding PC Hardware
      • What You Need to Know About the Course
      • About These Materials
    • unit2 hardware basice
      • PCH1 The Basics
      • PCH2 Procedures and Safety
      • PCH3 Customer Relations
  • python variable
    • keywords
      • input
      • print
    • 變數及基本運算
      • assign 指定
    • Dictionary 字典
  • 問題排除
    • 1 heading問題
    • 2 提醒
    • 3 user內容的方式
    • 4 github page not updating
    • 5 網站編輯器無法開啟
    • 6 usb的問題總結
    • 7 同學大部分的問題和集 舊版
  • 教學歷程
    • W1至W8
    • W8 test
    • W9
  • HW2
    • HW2之1
    • HW2之2
    • HW2之3
  • 同學的問題集中串
  • 打開動態網站的方法
  • pyrhon學習網站
    • 英文
    • 中文
HW2 << Previous Next >> HW2之2

HW2之1

設計一甲

import urllib.request
url = "https://nfulist.herokuapp.com/?semester=1091&courseno=0762"
cp1a = []
for line in urllib.request.urlopen(url):
    cp1a.append(int(line.decode('utf-8').rstrip()))
print(cp1a)
print("總共有" + str(len(cp1a)) + " 筆")
total = len(cp1a)
for i in range(total):
    print("http://github.com/" + str(cp1a[i]) + "/cp2020")

1. import urllib.request

    導入 urllib.request: https://docs.python.org/3/library/urllib.request.html

    並且透過urllib.request 模組中的 urlopen() 開啟網路 url 連結資料

2. url = "https://nfulist.herokuapp.com/?semester=1091&courseno=0762"

    設定名單的源頭從https://nfulist.herokuapp.com/?semester=1091&courseno=0762這個網址來

3.cp1a = []

   設定cp1a這個數列

4. for line in urllib.request.urlopen(url):
    cp1a.append(int(line.decode('utf-8').rstrip()))

    透過 urllib.request模組裡的urlopen()取下網際資料但由於資料為binary格式所以必須使用utf-8進行      編碼將它轉換成我們可看得懂的數字

5. print(cp1a)

    顯示cp1a , 由於前面有定義數列了所以cp1a的資料將以數列方式呈現

6. print("總共有" + str(len(cp1a)) + " 筆")

    顯示 總共有+字串cp1a的資料數+筆

7. total = len(cp1a)

    設定total為cp1a資料數

8. for i in range(total):
    print("http://github.com/" + str(cp1a[i]) + "/cp2020")

    用迴圈下去跑(total的資料數)相同的次數 

    並顯示http://github.com/+ cp1a資料裡每個數據 + /cp2020


HW2 << Previous Next >> HW2之2

Copyright © All rights reserved | This template is made with by Colorlib