---
# System prepended metadata

title: '**Python 期末考**'

---

# **Python 期末考**
## **學號:411008034 姓名:溫婕寧**
***
### Problem1
**程式碼**
```
import csv

def main():
    out=[]
    try:
        with open(students.csv,'r') as cc:
```
![](https://i.imgur.com/vOI126q.png)


**結果**
無

### Problem2
**程式碼**
```
class ID:
    def __init__(self, id = "0"):
        self.id = id
    def __str__(self):
        return f"student is  {self.id}"

student = ID("411123001")
print(student)
student = ID("411125001")
print(student)
student = ID("411103001")
print(student)
student = ID("411101001")
print(student)
student = ID("411123002")
print(student)
student = ID("411123003")
print(student)
student = ID("411102001")
print(student)
student = ID("411102002")
print(student)
student = ID("411103001")
print(student)
student = ID("411121001")
print(student)

class Department:
    def __init__(self, d = "0"):
        self.d = d
    def __str__(self):
        return f"student is  {self.d}"

student = Department("電機系")
print(student)
student = Department("光電系")
print(student)
student = Department("歷史系")
print(student)
student = Department("中文系")
print(student)
student = Department("電機系")
print(student)
student = Department("電機系")
print(student)
student = Department("英美系")
print(student)
student = Department("英美系")
print(student)
student = Department("中文系")
print(student)
student = Department("資工系")
print(student)

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


**結果**
![](https://i.imgur.com/epPtxkX.png)



### Problem3
**程式碼**
```
import re
import csv

def main():

    check(id)
    out=[]
    f = open('information.txt')
    for row in f.readlines():
        out.append(row)
        print(out)
    f.close
    if id in out:
        print(f'{"tel"}')
    else:
        print('ID is not exist.')


def check(id):
    while True:
        id=input('input st:')
        if re.search('[a-zA-Z0-9]{7,11}',id):
            return True
        else:
            print('Wrong ID,please try again.')
            continue


if __name__=="__main__":
    main()
```
![](https://i.imgur.com/25ajc1H.png)



**結果**
![](https://i.imgur.com/E5JvPCv.png)
