---
# System prepended metadata

title: '*2022/05/20 網路爬蟲 HW03*'
tags: [網路爬蟲]

---

###### tags: `網路爬蟲`
# *2022/05/20 網路爬蟲 HW03*
## 題目：
![](https://i.imgur.com/p5dEIF8.png)
## 引用模組程式碼：
```
#模組名稱:Create_Module
def function_1(value_1,value_2=10):
    answer = 0
    for i in range(value_1,value_2+1,1):
        answer = answer + i
    return answer

def function_2(str):
    str_rev = str[len(str)::-1]
    if str == str_rev:
        return True
    else:
        return False

```
## 主程式:
```
import Create_Module as CM

print(CM.function_1(2))
print(CM.function_1(6,20))

print(CM.function_2('船上女子叫子女上船'))
print(CM.function_2('MadaM'))
print(CM.function_2('python'))

```
## 輸出結果:
![](https://i.imgur.com/W5jFbEs.png)

![](https://i.imgur.com/ajwEopo.png)

```
with open('Poetry.txt', 'w', encoding='utf-8') as file:
    file.write('杜秋娘【金縷衣】\n\n勸君莫惜金縷衣\n勸君惜取少年時\n花開堪折直須折\n莫待無花空折枝')

f = open('Poetry.txt', 'r', encoding='utf-8')
print(f.read())
f.close()
```
![](https://i.imgur.com/CsmpA2U.png)

![](https://i.imgur.com/0Nk9LHj.png)
```
import json

my_dict = {
    '學員':{
        '學號':543,
        '姓名':'王大明',
    },
    '課程':[
        {
            '課程名稱':'Python程式設計',
            '成績':90
        },
        {
            '課程名稱':'JavaScript網頁程式設計',
            '成績':80
        }
    ]
}
with open('output.txt', 'w', encoding='utf-8') as f:
    json.dump(my_dict, f, ensure_ascii=False)

with open('output.txt', 'r', encoding='utf-8') as f:
    d = json.load(f)

print(json.dumps(d, indent=4, ensure_ascii=False))
```
## 輸出結果:
![](https://i.imgur.com/QLTVujr.png)

![](https://i.imgur.com/Jzh7gm2.png)
```
while True:
    try:
        x = int(input('x='))
        break
    except Exception:
        print('輸入內容必須為整數，請重新輸入')
while True:
    try:
        y = int(input('y='))
        break
    except Exception:
        print('輸入內容必須為整數，請重新輸入')

print('x+y=%d' %(x+y))
```
## 輸出結果:
![](https://i.imgur.com/gL1mnI0.png)
![](https://i.imgur.com/YCTNTB8.png)

