---
# System prepended metadata

title: Untitled

---

![](https://hackmd.io/_uploads/BkU0qhT8h.png)
![](https://hackmd.io/_uploads/rJndo2pU3.png)
![](https://hackmd.io/_uploads/rkkxnhTUn.png)
![](https://hackmd.io/_uploads/S1JQ2hp82.png)
不知道怎麼合併ＱＱ
有放在同一頁
![](https://hackmd.io/_uploads/rJB4yaa8n.png)
![](https://hackmd.io/_uploads/H1dEJp68h.png)
![](https://hackmd.io/_uploads/Hk5VJaa8n.png)
結果跑不出來
![](https://hackmd.io/_uploads/rkNIW66Ln.png)

#讀取資料
import pandas as pd

data = pd.read_csv('https://github.com/cwstedctw/NDHU-Python-Course/raw/main/student_info.txt', delimiter='\t')
data.to_excel('student_info.xlsx', index=False)

#判斷電話是否正確
def validate_phone_number(phone_number):
    area_codes = {
        "02": ["新北市", "基隆市", "桃園市龜山區迴龍"],
        "03": ["桃園市", "新竹市", "新竹縣", "花蓮縣", "宜蘭縣"],
        "037": ["苗栗縣", "新竹縣峨眉鄉部份"],
        "04": ["臺中市", "苗栗縣卓蘭鎮", "南投縣仁愛鄉部分", "花蓮縣秀林鄉富世村關原地區"],
        "049": ["南投縣", "彰化縣芬園鄉", "臺中市烏日區溪尾里、新社區福興里部份、不含仁愛鄉部分", "部分花蓮縣秀林鄉富世村關原地區"],
        "05": ["嘉義市", "嘉義縣（六腳鄉及新港鄉部份地區）", "雲林縣"],
        "06": ["臺南市", "澎湖縣"],
        "07": ["高雄市"],
        "08": ["屏東縣"],
        "089": ["臺東縣"],
        "082": ["金門縣"],
        "0826": ["金門縣烏坵鄉"],
        "0836": ["連江縣"]
    }

    area_code = phone_number[:2]
    if area_code in area_codes:
        return True, area_codes[area_code]
    else:
        return False, []

phone_number = input("Phone：")

valid, areas = validate_phone_number(phone_number)
if valid:
    print("Pass")

else:
    print("Fail")
#check student_no
import re

def validate_student_no(student_no):

    if len(student_no) != 9:
        return False


    pattern = r"^[468][0-9]{3}([1-9]|1[0-6]|21|22|23)([0-2][0-9]|3[0-3])([0-9]{2})$"
    if not re.match(pattern, student_no):
        return False


    identity_code = int(student_no[6])
    if identity_code not in [0, 1, 2, 3]:
        return False

    return True


#check id

   import re

def validate_id(id_number):
    pattern = r'^[A-Z][12]\d{8}$'
    if not re.match(pattern, id_number):
        return False

    letters = 'ABCDEFGHJKLMNPQRSTUVXYWZIO'
    letter_value = {'A': 10, 'B': 11, 'C': 12, 'D': 13, 'E': 14, 'F': 15, 'G': 16, 'H': 17, 'J': 18, 'K': 19, 'L': 20, 'M': 21,
                    'N': 22, 'P': 23, 'Q': 24, 'R': 25, 'S': 26, 'T': 27, 'U': 28, 'V': 29, 'X': 30, 'Y': 31, 'W': 32, 'Z': 33,
                    'I': 34, 'O': 35}
    id_letters = id_number[:-1]
    last_letter = id_number[-1]
    region = id_letters[0]
    gender = id_letters[1]
    serial_number = id_letters[2:]

    if region not in letters:
        return False

    if gender not in ['1', '2']:
        return False

    if not serial_number.isdigit() or len(serial_number) != 7:
        return False

    total = letter_value[region] // 10 + (letter_value[region] % 10) * 9
    total += int(gender) * 8 + int(serial_number[0]) * 7 + int(serial_number[1]) * 6 + int(serial_number[2]) * 5
    total += int(serial_number[3]) * 4 + int(serial_number[4]) * 3 + int(serial_number[5]) * 2 + int(serial_number[6])
    check_digit = (10 - (total % 10)) % 10

    if check_digit != int(last_letter):
        return False

    return True

id_number = input("ID: ")
if validate_id(id_number):
    print("True")
else:
    print("False")



