攝影或3C

Python TQC考題606: 檢驗學號

範例輸入/輸出:

code:

# -*- coding: utf-8 -*-
"""
Created on Sun Nov 19 00:29:15 2023

@author: SavingKing
"""

def chk(strr):
    strr_5 = strr[:-1]
    #'12345'
    
    lis_int = [eval(i) for i in strr_5]
    
    s0 = lis_int[0]
    s2 = lis_int[2]
    s4 = lis_int[4]
    
    s1 = lis_int[1]
    s3 = lis_int[3]
    
    result = ((s0+s2+s4)+(s1+s3)*5)%26
    
    dic = {1:"A",
           2:"B",
           13:"M"}
    
    if dic[result] == strr[-1]:
        check = True
    else:
        check=False

    return check

lis=[]
for i in range(3):
    strr=input("請輸入學號:\t")
    lis.append(strr)
"""
12345M
55237B
03805A
"""
for ele in lis:
    if chk(ele):
        print("Pass")
    else:
        print("Fail")

輸出結果:

推薦hahow線上學習python: https://igrape.net/30afN

儲蓄保險王

儲蓄險是板主最喜愛的儲蓄工具,最喜愛的投資理財工具則是ETF,最喜愛的省錢工具則是信用卡