日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

python小作业初版之信用卡交易

發(fā)布時間:2023/12/20 python 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python小作业初版之信用卡交易 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

完全沒有異常處理。還在學(xué)習(xí)中。。。部分代碼還能再寫成函數(shù)。

#!/usr/bin/python import sys import pickle import os import getpass import time def login(username = '',password = '',user_type = 1):print 'Welcome 2 ATM Basic System.'error_count = 0initInfo(info_list)pkl_file = file('userInfo.pkl','rb')dic_account = pickle.load(pkl_file)pkl_file.close()while True:username = str(raw_input('please input your username or quit(q): ').strip())if len(username) == 0:print 'Invalid Username!'elif username in ('q','quit'):sys.exit()elif username not in dic_account.keys():print 'No %s found!' % usernameelse:password = str(dic_account[username][0])type = int(dic_account[username][-1])if type == 2:print 'Account %s is Lock!Please contact your Admin.' % usernamesys.exit()else:while True:pass_input = getpass.getpass('please input your password: ')if pass_input != password:print 'Wrong Password!'error_count += 1if error_count == 3:print 'You give the wrong password 3 times.now exit!'dic_account[username][-1] = 2dicDump(dic_account)sys.exit()else:continueelse:if type == 1:while True:print 'Welcome,%s' % usernameprint '*'*20print '1.Go Shopping'print '2.Withdraw'print '3.Repay'print '4.Show Detail'print '0.quit'print '*'*20choice = int(raw_input('Please choose one option: ').strip())if choice == 1:goShopping(username,dic_account)elif choice == 2:withDraw(username,dic_account)elif choice == 3:rePay(username,dic_account)elif choice == 4:showDetail(username,dic_account)elif choice == 0:sys.exit()else:print 'please choose one option with int 1/2/3/4/0.'else:while True:print 'Welcome!Admin %s' % usernameprint '*'*20print '1.Add User'print '2.Edit User'print '3.Show All'print '0.quit'print '*'*20choice = int(raw_input('Please choose one option: ').strip())if choice == 1:addUser(dic_account)elif choice == 2:editUser(dic_account)elif choice == 3:showAll(dic_account) elif choice == 0:sys.exit()else:print 'please choose one option with int 1/2/3/4/0.' def initInfo(info_list):if not os.path.exists('userInfo.pkl'):pkl_file = open('userInfo.pkl','wb')pickle.dump(info_list,pkl_file)pkl_file.close()else:pass def dicDump(dic_account):pkl_file = open('userInfo.pkl','wb')pickle.dump(dic_account,pkl_file)pkl_file.close()def goShopping(username,dic_account):shopList = {'Computer':4999,'Phone':3999,'Music Player':1688,'Coffee':27}for item in shopList:print '%s => %s' % (item,shopList[item])while True:each = raw_input('which one are you gonna buy?').strip()if each in ('q','quit','exit'):breakelif each not in shopList.keys():print 'No %s in the shopping list!retry!' % eachelse:if dic_account[username][2] >= shopList[each]:f = file('detail.log','a')f.write('%s\t%s\t%s\t%s\t0\n' % (username,time.strftime('%y-%m-%d %H:%M:%S',time.localtime()),each,shopList[each]))f.close()dic_account[username][2] -= shopList[each]dicDump(dic_account)print 'You have bought %s,it takes you %d yuan.now you have a balance of %d.' % (each,shopList[each],dic_account[username][-2])else:print 'You have not enough money to offord it!'break def withDraw(username,dic_account):draw_count = int(raw_input('How much Cash withdrawal? '))while True:if (draw_count*105/100) > dic_account[username][2]:print 'Oops!You have not enough Amount to Cash withdrawal!Your balance now is %s !'% (dic_account[username][2])breakelse:dic_account[username][2] -= draw_countdicDump(dic_account)f = file('detail.log','a')f.write('%s\t%s\tCash withdrawal\t%s\t%s\n' % (username,time.strftime('%y-%m-%d %H:%M:%S',time.localtime()),draw_count,(draw_count*5/100)))f.close()print 'For now,your balance is %d'% (dic_account[username][2])break def rePay(username,dic_account):save_count = int(raw_input('How much Cash to save? '))dic_account[username][2] += save_countdicDump(dic_account)f = file('detail.log','a')f.write('%s\t%s\tRepay\t%s\t0\n' % (username,time.strftime('%y-%m-%d %H:%M:%S',time.localtime()),save_count))f.close()print 'For now,your balance is %d'% (dic_account[username][2]) def showDetail(username,dic_account):if not os.path.exists('detail.log'):print 'Your Detail List is Empty!'print 'Your max permit is %s,now your balance is %s.\n'%(dic_account[username][1],dic_account[username][2])else:print 'Your max permit is %s,now your balance is %s.\n'%(dic_account[username][1],dic_account[username][2])f = file('detail.log','r')for eachLine in f:if eachLine.startswith(username):print eachLineelse:passf.close() def addUser(dic_account):add_username = str(raw_input('What\'s the user\'s name? ').strip())if len(add_username) == 0:print 'Invalid User Name!'elif add_username.lower() in dic_account.keys():print 'User Already Exists@!'else:while True:add_passwd = getpass.getpass('Please input the password: ')if len(add_passwd) < 6:print 'Password\'s len must longer than 6 letters!'breakelse:add_passwd_again = getpass.getpass('Please input the password again: ')if add_passwd_again != add_passwd:print 'password is\'t same as the first time input!'breakelse:add_user_balance = int(raw_input('Define a max balance number: '))dic_account[add_username] = [add_passwd,add_user_balance,add_user_balance,1]dicDump(dic_account)print 'Add %s success!Amount is %d.'% (add_username,add_user_balance)break def editUser(dic_account):edit_username = str(raw_input('Which user do you want to edit? ').strip())if len(edit_username) == 0:print 'Invalid User Name!'elif edit_username.lower() not in dic_account.keys():print 'User Doesn\'t Exists@!'else:while True:print '\n\t1.Change The Max Balance'print '\t2.Change Password'print '\t3.Lock/Unlock The User'edit_choice = int(raw_input('Please Choose one option or quit!: '))if edit_choice == 1:edit_user_balance = int(raw_input('Define a max balance number to Change: '))dic_account[edit_username][1] = edit_user_balancedicDump(dic_account)breakelif edit_choice == 2:edit_user_passwd = getpass.getpass('Please input the password : ')dic_account[edit_username][0] = edit_user_passwddicDump(dic_account)breakelif edit_choice == 3:edit_user_type = int(raw_input('Lock => 2,Unlock => 1: '))dic_account[edit_username][-1] = edit_user_typedicDump(dic_account)breakelse:print 'Please retry,just use the int 1/2/3!'break def showAll(dic_account):for each_user in dic_account.keys():print '*'*20print '%s\'s Max Amount is %d,now Balance is %d.\n' % (each_user,dic_account[each_user][1],dic_account[each_user][2])f = file('detail.log','r')for eachLine in f:if eachLine.startswith(each_user):print eachLineelse:passf.close() info_list = {'fengxsong':['p@55w0rd',15000,15000,0],'nagios':['nagios',9000,9000,1]} if __name__ == '__main__':login()


轉(zhuǎn)載于:https://blog.51cto.com/fengxs/1404354

總結(jié)

以上是生活随笔為你收集整理的python小作业初版之信用卡交易的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。