1.工作流程
2.模擬自動(dòng)存取款機(jī)的操作
代碼如下:
import msvcrt, sys, os #定義用星號(hào)隱藏密碼輸入的函數(shù) def psw_input(): li = [] while True: ch = msvcrt.getch() #回車 if ch == b'\r': msvcrt.putch(b'\n') break #退格 elif ch == b'\x08': if li: li.pop() msvcrt.putch(b'\b') msvcrt.putch(b' ') msvcrt.putch(b'\b') #Esc elif ch == b'\x1b': break else: li.append(ch) msvcrt.putch(b'*') return li #定義CSDN銀行ATM歡迎界面的函數(shù) def ATM(): ''' CSDN銀行ATM歡迎界面的函數(shù) ''' print("="*14,"Bank of CSDN","="*14,"\n") print("{:^42}".format("ATM"),"\n") print("="*14,"Bank of CSDN","="*14,"\n") #CSDN銀行用戶列表信息,用戶信息包含:姓名、余額、密碼(6位)、銀行卡號(hào)(19位) user_list = [{"name":"張 三","balance":10000,"password":"000000","numbers":"0000000000000000000"}, {"name":"李 四","balance":20000,"password":"111111","numbers":"1111111111111111111"}, {"name":"王 五","balance":30000,"password":"222222","numbers":"2222222222222222222"}] #定義驗(yàn)證銀行卡號(hào)與密碼匹配的函數(shù) def check(user_name,user_password): ''' 驗(yàn)證銀行卡號(hào)與密碼匹配的函數(shù) ''' for i in range(len(user_list)): if user_name == user_list[i]["numbers"] and user_password == user_list[i]["password"]: return i #銀行卡號(hào)與密碼匹配則返回該用戶在ATM系統(tǒng)內(nèi)的ID值,否則返回None值 #定義用戶登錄成功后操作界面的函數(shù) def interface(): ''' 用戶登錄成功后操作界面的函數(shù) ''' print("="*14,"用戶操作界面","="*14,"\n") print("{0:2} {1:12} {2:12} {3:12}".format(" ","1. 查詢","2. 取款","3. 存款"),"\n") print("{0:2} {1:10} {2:12}".format(" ","4. 修改密碼","5. 退出"),"\n") print("="*42,"\n") #定義用戶查詢信息的函數(shù) def inquire(user_id): ''' 用戶查詢信息的函數(shù) ''' print("="*14,"賬號(hào)查詢界面","="*14,"\n") print("|{0:<4}|{1:<18}|{2:<9}|\n".format("賬戶名","卡號(hào)","余額(RMB)")) print("|{0:<5}|{1:<20}|{2:<11}|\n".format(user_list[user_id]["name"],user_list[user_id]["numbers"],user_list[user_id]["balance"])) #定義用戶取款的函數(shù) def withdrawal(amount): ''' 用戶取款的函數(shù) ''' i = user_list[user_id]["balance"]-int(amount) if i>=0: user_list[user_id]["balance"]-=int(amount) else: print("賬戶余額不足\n") #定義用戶存款的函數(shù) def deposit(amount): ''' 用戶存款的函數(shù) ''' user_list[user_id]["balance"]+=int(amount) #定義用戶修改密碼的函數(shù) def change_password(old_password,new_password1,new_password2): ''' 用戶修改密碼的函數(shù) ''' if old_password == user_list[user_id]["password"]: if new_password1 == new_password2: user_list[user_id]["password"] = new_password1 print("新密碼修改成功\n") return 1 else: print("修改密碼失敗,您2次輸入的新密碼不一致\n") return 2 else: print("舊密碼輸入錯(cuò)誤\n") return 0 #用戶登錄界面,輸入銀行卡號(hào)和密碼 chance = 3 #允許3次用戶名或密碼輸入錯(cuò)誤 while True: ATM() user_name = input("請(qǐng)輸入您的銀行卡卡號(hào):") print("") print("請(qǐng)輸入您的銀行卡密碼:", end=' ', flush=True) user_password = b''.join(psw_input()).decode() print("") user_id = check(user_name,user_password)#驗(yàn)證銀行卡號(hào)與密碼是否匹配 if user_id != None: print("登錄成功\n") while True: interface() key_word = input("請(qǐng)輸入操作選項(xiàng):") print("") if key_word == "1": inquire(user_id) input("按任意鍵返回上一級(jí)目錄:") print("") elif key_word == "2": print("="*14,"賬號(hào)取款界面","="*14,"\n") amount = input("請(qǐng)輸入取款金額:") print("") withdrawal(amount) inquire(user_id) input("按任意鍵返回上一級(jí)目錄:") print("") elif key_word == "3": print("="*14,"賬號(hào)存款界面","="*14,"\n") amount = input("請(qǐng)輸入存款金額:") print("") deposit(amount) inquire(user_id) input("按任意鍵返回上一級(jí)目錄:") print("") elif key_word == "4": print("="*14,"密碼管理界面","="*14,"\n") print("請(qǐng)輸入舊密碼:", end=' ', flush=True) old_password = b''.join(psw_input()).decode() print("") print("請(qǐng)輸入新密碼:", end=' ', flush=True) new_password1 = b''.join(psw_input()).decode() print("") print("請(qǐng)?jiān)俅屋斎胄旅艽a:", end=' ', flush=True) new_password2 = b''.join(psw_input()).decode() print("") save = change_password(old_password,new_password1,new_password2) #如何檢測(cè)到舊密碼輸入有誤,將直接退出 if save == 0: break elif key_word == "5": print("="*14,"歡迎下次光臨","="*14,"\n") break else: print("="*14,"沒有該選項(xiàng)","="*14,"\n") else: if chance > 1: print("用戶名或密碼錯(cuò)誤,您還有",chance-1,"次機(jī)會(huì),請(qǐng)重新輸入\n") chance -= 1 else: print("對(duì)不起,您輸入用戶名或密碼錯(cuò)誤已達(dá)3次") break
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。
新聞名稱:Python模擬自動(dòng)存取款機(jī)的查詢、存取款、修改密碼等操作-創(chuàng)新互聯(lián)
本文地址:http://vcdvsql.cn/article12/ddgddc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)建站、網(wǎng)站導(dǎo)航、云服務(wù)器、虛擬主機(jī)、網(wǎng)站制作、域名注冊(cè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容