---
# System prepended metadata

title: 第十二堂課練習 - file
tags: [Python]

---

###### tags: `Python`

# 第十二堂課練習 - file

```python=
file = open("paper.txt","w")     # w:寫入

file.write("Good morning\n")     # \n = 換行
file.write("午安")
file.close()

print("存檔完畢")                 # Good morning自動記事本存檔                      
```
:::spoiler 執行結果
![](https://i.imgur.com/OsXht0a.png)
![](https://i.imgur.com/tGrAqCF.png) 
:::
```python=
file = open("paper.txt","a")    # a:附加，不會覆蓋舊資料

file.write("Aloha!!\n")

file.close()

print("存檔完畢")
```
:::spoiler 執行結果
![](https://i.imgur.com/OsXht0a.png)
![](https://i.imgur.com/d6H10HQ.png)
:::
```python=
while True:   
    n = eval(input("1.新增會員  2結束\n"))

    if n == 1:
        name =(input("帳號："))
        passwd =(input("密碼："))
        file = open("member.csv","a")
        file.write(name +","+ passwd + "\n")
        file.close()
        print("ok!!")
    else:
        break
```
:::spoiler 執行結果
![](https://i.imgur.com/OXhflMk.png)

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