この記事に含まれる主なメソッドは、Pythonのopen(filename、 'r')でファイルを読み取り、open(filename、 'w')でファイルを書き込み、ファイルを書き込みで開きます。for* in *を使用してデータを読み取ります。ファイルまたはファイルデータを書き込み、dict(eval(list2))メソッドを使用して文字列を辞書に変換します。
詳細なコードは次のとおりです。
#刘文豪 #大帅哥 輸入数学の 再インポート デフメイン():#メイン機能 = True]を選択 しながら(選択): メニュー() start_int =入力(「操作したい機能のシリアル番号を選択してください:」) の場合start_int = = "12": select = False print( "すでにシステムを終了しており、次回も よろしくお願いします")elif start_int == "4": insert() elif start_int == "5": login() elif start_int == "6": show() elif start_int == "11": delete() elif start_int == "7": revise ()elif start_int == "8": 預金()) print( "11 ========個人情報のキャンセル==========") elif start_int == "9": getMoney() elif start_int == "10": UseMoney() def menu():#メニュー表示 print( "1 ========銀行の入出金システム=== ===== ") print(" 2 =========================== ") print(" 3 ====== =====機能メニュー=========== ") print(" 4 =========個人情報の登録========== ") print( "5 ============ログイン=============") print( "6 =========個人情報の照会==== ====== ") print(" 7 =========個人アカウントの変更========== ") print(" 8 ========== ==お金を節約する============= ") print(" 9 ============お金を引き出す============= ") print(" 10 =========年収を表示========== ") print("12 =========== Exit ============= ") filename =" Bank.txt "#ユーザー情報を保存するためのファイル名を定義します def save(Bank):#ファイルメソッドの作成 try: Bank_txt = open(filename、 " a ") 例外を除くe: Bank_txt = open(filename、" w ") for info in Bank: Bank_txt.write(str(info)+" \ n ") Bank_txt.close() def insert():#登録方法 BankList = []#ユーザー情報リストを保存 mark = True# しばらくの間追加を続行するかどうかmark: id = input( "IDパスワード(1001など)を入力してください:") if not id: break name = input( "あなたの名前 ")名前で ない場合: break try: deposit = int(input("入金したい金額を入力してください ")) デポジット== 0の場合: ブレーク を除きます: print( "入力が無効です。整数ではありません。再入力してください") continue Bank = {"id":id、 "name":name、 "deposit":deposit} BankList.append(Bank) mark = False save (BankList) print( "Registered success ")global g_select g_select = 0 global Username global Userpassword def login():#ログイン方法 global Username global g_select global g_BankQuery global Userpassword g_BankQuery = [] Username = str(input( "ユーザーを入力してください名前 ")) Userpassword = str(input("パスワードを入力してください ")) file = open(filename、 'r') Bank = file。readlines()# 銀行のリストのすべてのコンテンツを読み取ります: d = dict(eval(list))# d ['name'] ==ユーザー名およびd ['id'] ==ユーザーパスワード: g_BankQueryの場合、文字は辞書に変換されます。 append(d) print( "Login success !")g_select = 1 else: pass if not g_BankQuery: g_select = 0 print( "Login failed、please register first!") else: pass def show():#個人情報を照会する if g_select = = 1: format_title = "{:^ 6} {:^ 12}" print(format_title.format( "name"、 "deposit")) format_date = "{:^ 6} {:^ 12}" for info g_BankQueryで: print(format_date.format(str(info.get( '名前 '))、str(info.get('預金 ')))) else: print( "最初にログインしてください!") def delete():#個人アカウントメソッドを削除します global g_BankQuery cz = [] global g_select choice = 0 if g_select == 1: while choice <3: username = str(input( "Please enter your name")) userpassword = str( input( "パスワードを入力してください")) file = open(filename、 'r') Bank = file.readlines()# Bank内のリストのすべてのコンテンツを読み取ります: d = dict(eval(list))# d ['name']の場合、文字は辞書に変換されます==ユーザー名とd ['id'] ==ユーザーパスワード: cz.append(d) file.close() choose = 3 NewBank = open(filename、 'w')# バンクのlist2に書き込むことでファイルを開きます: d2 = dict(eval(list2))#文字を辞書に変換します ようにif d2 ['name']!= username and d2 ['id']!= userpassword: NewBank.write(str (d2)+ "\ n") else: pass else: pass if not cz: choose = choice + 1 if choice == 3:g_select = 0 print( "もう一度ログインしてください!") else: print( "Username Orパスワードが間違っています。まだ持っているものを再入力してください:」+ str(3-choose)+ "opportunity") else: を銀行のlist2: g_BankQuery。clear() g_select = 0 print( "あなたの個人情報はキャンセルされました") else: print( "最初にログインしてください!") def revise ():#個人アカウントメソッドを変更します cz = [] global g_select if g_select == 1: username = input( "ユーザー名を入力してください:") userpassword = input( "パスワードを入力してください:") file = open(filename、 'r') Bank = file.readlines()# バンク内のリストのすべてのコンテンツを読み取ります: d = dict(eval(list))#文字は辞書に変換されます if d ['name'] ==ユーザー名とd ['id'] == userpassword: cz.append(d ) file.close ()NewBank = open(filename、 'w')# d2 = dictと記述してファイルを開きます(eval(list2))#文字は辞書に変換されます if d2 ['name'] == username and d2 ['id'] == userpassword: d2 ['name'] = input( "Enter your new name:") d2 ['id'] = input( "input Your新しいパスワード: ") NewBank.write(str(d2)+" \ n ") print("正常に変更されました。もう一度ログインしてください! ") g_select = 0 else: NewBank.write(str(d2)+" \ n " ) else: pass if not cz: print( "入力したパスワードまたはユーザー名が正しくあり ません。もう一度ログインしてください") g_select = 0 else: pass 他の: print( "最初にログインしてください!") def預金():# 預金メソッドグローバルg_BankQuery global g_select cz = [] if g_select == 1: money = int(input( "入金する金額を入力してください:")) file = open(filename、 'r') Bank = file.readlines()# バンク内のリストのすべてのコンテンツを読み取ります 。d= dict(eval(list))# d ['name'] ==ユーザー名およびd ['id'] ==ユーザーパスワードの場合、文字は辞書に変換されます: cz.append(d) file .close ()NewBank = open(filename、 'w')#Bankのlist2に書き込むこと でファイルを開きます: d2 = dict(eval(list2))#文字を辞書に変換します NewBank。write(str(d2)+ "\ n") D2 [ '名前'] ==ユーザー名とd2 [ 'ID'] ==ユーザー・パスワードの場合: d2 ['deposit'] = str(int(d2 ['deposit'])+ money) print( "Save success !")g_BankQuery.clear() g_BankQuery.append(d2) else: NewBank.write(str(d2) + "\ n") else: pass else: print( "最初にログインしてください!") def getMoney():#お金を 引き出すメソッドglobal g_select global g_BankQuery cz = [] if g_select == 1: money = int(input( "引き出したい金額を入力してください: ")) file = open(filename、 'r') Bank = file。readlines()# 銀行のリストのすべてのコンテンツを読み取ります: d = dict(eval(list))#文字は辞書に変換されます d [' name 'の場合、 cz.append(d) if money> int(d ['deposit']): print( "残高が不十分です") else: file.close ()NewBank = open(filename、 'w')#Bankのlist2に書き込むこと でファイルを開きます: d2 = dict(eval(list2))# d2 ['name'] ==ユーザー名とd2 ['の場合、文字は辞書に変換されますid '] == Userpassword: d2 [' deposit '] = str(int(d2 [' deposit '])-money) NewBank.write(str(d2)+ "\ n") print( "お金を正常に引き出します!") g_BankQuery.clear() 引き出し g_BankQuery。append(d2) else: NewBank.write(str(d2)+ "\ n") else: pass else: print( "最初にログインしてください!") def UseMoney():#利息計算 UM = True while UM: try: money = float(input ( "財務管理に投資する金額を入力してください:")) year = int(input( "保存する年数を入力してください:")) except: print( "整数の年を入力してください!" ) if 0 <year <= 3: profitmargin = 0.03 elif 3 <year <= 5: profitmargin = 0.04 elif 5 <year <= 10: profitmargin = 0。06 elif year> 10: profitmargin = 0。08 お金<0または年<= 0の場合: print( "元本は0元未満、年は0年未満にすることはできません") else: UM = False Profit = round(money * year * Profitmargin、3) print( "You save:" + str(year )+ "年間利益は次のようになります:" + str(profit)+ "元元と利益は次のようになります:" + str(profit + money)+ "yuan") if __name__ == "__ main__": 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
ランニング写真:
最近、多くの友人がプライベートメッセージを通じてPythonの学習問題について相談しました。コミュニケーションを促進するには、青をクリックしてディスカッションに参加し、自分でリソースベースに回答してください