Python__模拟实现一个ATM+购物商城程序
生活随笔
收集整理的這篇文章主要介紹了
Python__模拟实现一个ATM+购物商城程序
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
需求:
模擬實(shí)現(xiàn)一個(gè)ATM+購(gòu)物商城程序
1.額度1500或者自定義
2.實(shí)現(xiàn)購(gòu)物商城,買東西加入購(gòu)物車,調(diào)用信用卡接口
3.可以提現(xiàn),手續(xù)費(fèi)5%
4.支持賬戶登錄
5.支持賬戶間轉(zhuǎn)賬
6.記錄每日日常消費(fèi)流水
7.提供還款接口
8.ATM記錄操作日志
9.提供管理接口,包括添加賬戶,用戶額度,凍結(jié)賬戶等
10.用戶認(rèn)證用裝飾 1 #Author wangmengzhu 2 ''' 3 用戶認(rèn)證,確認(rèn)是用戶登錄,判斷用戶登錄的用戶名和密碼是否正確,判斷用戶認(rèn)證的長(zhǎng)度是否為0,使用裝飾器 4 用戶登錄認(rèn)證,信用卡登錄認(rèn)證,管理員登錄認(rèn)證 5 ''' 6 import time,os 7 def auth(auth_type): 8 ''' 9 用戶的認(rèn)證信息 10 ''' 11 def my_wrapper(func): 12 if auth_type == 'user_auth': 13 def wrpper(*args,**kwargs): 14 name = input('請(qǐng)輸入你的用戶名>>: ').strip() 15 password = input('請(qǐng)輸入你的密碼>>: ').strip() 16 if len(name) > 0: 17 with open('用戶名和密碼.txt','r',encoding = 'utf-8') as f: 18 line = f.read() 19 my_dic = eval(line) 20 if name in my_dic and password == my_dic[name]: 21 print('%s歡迎登陸'%(name)) 22 func(*args,**kwargs) 23 else: 24 print('%s認(rèn)證失敗'%(name)) 25 else: 26 print('輸入的用戶名不能為空') 27 return wrpper 28 elif auth_type == 'credit_auth': 29 def wrpper(*args, **kwargs): 30 credit_number = input('請(qǐng)輸入你的信用卡號(hào)>>: ').strip() 31 credit_password = input('請(qǐng)輸入你的信用卡密碼>>: ').strip() 32 if len(credit_number) == 10: 33 with open('信用卡號(hào)和密碼.txt','r',encoding = 'utf-8') as f: 34 line = f.read() 35 my_dic = eval(line) 36 if credit_number in my_dic and credit_password == my_dic[credit_number]: 37 print('認(rèn)證成功,歡迎登陸') 38 func(*args, **kwargs) 39 else: 40 print('認(rèn)證不成功') 41 else: 42 print('輸入的信用卡號(hào)的長(zhǎng)度不對(duì)') 43 return wrpper 44 elif auth_type == 'admin_auth': 45 def wrpper(*args, **kwargs): 46 admin_name = input('請(qǐng)輸入你的管理員用戶名>>: ').strip() 47 admin_password = input('請(qǐng)輸入你的管理員密碼>>: ').strip() 48 if len(admin_name) > 0: 49 with open('管理員用戶名和密碼.txt', 'r', encoding='utf-8') as f: 50 line = f.read() 51 my_dic = eval(line) 52 if admin_name in my_dic and admin_password== my_dic[admin_name]: 53 print('%s歡迎登陸' % (admin_name)) 54 func(*args, **kwargs) 55 with open('日志模塊.txt', 'a+', encoding='utf-8') as f: 56 f.write('%s %s run' % (time.strftime('%Y-%m-%d %X'), func.__name__)) 57 else: 58 print('%s認(rèn)證失敗' % (admin_name)) 59 else: 60 print('輸入的用戶名不能為空') 61 62 return wrpper 63 return my_wrapper 64 @auth(auth_type = 'user_auth') 65 def user_auth(): 66 print('用戶登錄認(rèn)證'.center(20,'*')) 67 @auth(auth_type = 'credit_auth') 68 def credit_auth(): 69 print('信用卡認(rèn)證'.center(20,'*')) 70 @auth(auth_type = 'admin_auth') 71 def admin_auth(): 72 print('管理員認(rèn)證'.center(20,'*')) 73 74 ''' 75 購(gòu)物商城和購(gòu)物車 76 ''' 77 def shop_list(): 78 my_shop_list = [] 79 my_buy_list = [] 80 with open('商品列表.txt','r+',encoding = 'utf-8') as f: 81 for item in f: 82 item.split(',') 83 my_shop_list.append(item) 84 print('目前商品所在的信息'.center(20, '*')) 85 for j in my_shop_list: 86 print(j,end = '') 87 print('\n',end = '') 88 while True: 89 my_choice = input('請(qǐng)輸入想要購(gòu)買的商品序號(hào)>>: ').strip() 90 if my_choice.isdigit(): 91 my_choice = int(my_choice) 92 if my_choice < len(my_shop_list) and my_choice > 0: 93 my_buy = my_shop_list[my_choice] 94 print(my_buy) 95 with open('我的購(gòu)物列表.txt', 'a+', encoding='utf-8') as f: 96 f.write(my_buy) 97 break 98 else: 99 print('輸入的商品編號(hào)錯(cuò)誤') 100 continue 101 else: 102 print('輸入的數(shù)字不合法') 103 continue 104 105 106 ''' 107 清空購(gòu)物車 108 ''' 109 def my_delete_cart(): 110 while True: 111 my_cart = []#我的購(gòu)物車 112 with open('我的購(gòu)物列表.txt','r+',encoding = 'utf-8') as f: 113 for line in f: 114 my_cart.append(line) 115 if my_cart != []: 116 my_choice = input('是否清空購(gòu)物車,回答YES或者NO>>: ').strip() 117 print('我的購(gòu)物車中的商品'.center(20,'*')) 118 for j in my_cart: 119 print(j,end = '') 120 if my_choice =='YES': 121 with open('我的購(gòu)物列表.txt','w',encoding = 'utf-8') as f: 122 pass 123 print('購(gòu)物車已經(jīng)清空') 124 elif my_choice == 'NO': 125 print('請(qǐng)繼續(xù)購(gòu)物吧!') 126 else: 127 print('輸入不正確,請(qǐng)重新輸入') 128 else: 129 print('購(gòu)物車?yán)镞呥€沒有商品') 130 break 131 132 133 134 ''' 135 購(gòu)物車結(jié)算 136 ''' 137 def my_pay(): 138 while True: 139 print('購(gòu)物結(jié)算'.center(20,'*')) 140 my_cart = [] 141 my_trans = [] 142 with open('我的購(gòu)物列表.txt','r+',encoding = 'utf-8') as f: 143 for line in f: 144 my_cart.append(line) 145 if my_cart != []: 146 print('購(gòu)物車清單'.center(20,'*')) 147 for j in my_cart: 148 my_new = j.split(',') 149 my_trans.append(my_new) 150 money = sum([int(i[2]) for i in my_trans]) 151 print(money) 152 else: 153 print('你還沒有消費(fèi)過(guò),快去買點(diǎn)你心儀的商品吧!') 154 break 155 my_choice = input('是否進(jìn)行結(jié)賬[合計(jì)%s人民幣](請(qǐng)回答Y或者N)>>: '%(money)).strip() 156 if my_choice == 'N': 157 break 158 elif my_choice == 'Y': 159 credit_auth()#調(diào)用信用卡接口認(rèn)證 160 my_credit_num = input('請(qǐng)輸入你的信用卡號(hào)').strip() 161 with open('信用卡號(hào)和密碼.txt','r+',encoding = 'utf-8') as f: 162 line = f.read() 163 my_dic = eval(line) 164 if my_credit_num not in my_dic: 165 print('認(rèn)證的信用卡號(hào)不存在,請(qǐng)重新輸入') 166 else: 167 with open('信用卡號(hào)和資金.txt','r+',encoding = 'utf-8') as f1: 168 line1 = f1.read() 169 my_dic1 = eval(line1) 170 your_credit = input('請(qǐng)輸入你的信用卡號(hào)>>: ').strip() 171 your_password = input('請(qǐng)輸入你的密碼>>: ').strip() 172 if your_credit in my_dic1 and your_password == my_dic1[your_credit]: 173 print('你的賬戶總共的資金為%s'%(my_dic1[your_credit])) 174 your_limit = my_dic1[your_credit] - money 175 if your_limit >= 0: 176 my_dic1[your_credit] = your_limit 177 print('支付成功,當(dāng)前信用卡余額為%s'%(your_limit)) 178 else: 179 print('余額不足,請(qǐng)充值') 180 else: 181 print('輸入的密碼錯(cuò)誤,請(qǐng)重新輸入') 182 continue 183 ''' 184 信用卡信息 185 ''' 186 def credit_data(): 187 while True: 188 with open('信用卡號(hào)和資金.txt','r+',encoding = 'utf-8') as f: 189 my_msg = f.read() 190 my_dic = eval(my_msg) 191 your_choice = input('請(qǐng)輸入要查看信息的信用卡號(hào)>>: ').strip() 192 if your_choice in my_dic: 193 print('我的信用卡信息'.center(20,'*')) 194 print('持卡人信用卡號(hào)%s\n持卡人余額%s'%(your_choice,my_dic[your_choice])) 195 else: 196 print('你輸入的信用卡號(hào)不存在,請(qǐng)重新輸入') 197 continue 198 choice = input('是否選擇退出(是或者否)>>: ').strip() 199 if choice == '是': 200 print('歡迎下次查詢') 201 break 202 else: 203 continue 204 205 206 207 ''' 208 信用卡轉(zhuǎn)賬 209 ''' 210 def my_trans(): 211 while True: 212 with open('信用卡號(hào)和資金.txt','r+',encoding = 'utf-8') as f: 213 line = f.read() 214 my_dict = eval(line) 215 choice = input('請(qǐng)輸入信用卡號(hào)>>: ').strip() 216 if choice in my_dict: 217 current_money = my_dict[choice] 218 trans_account = input('請(qǐng)輸入你要轉(zhuǎn)賬的賬號(hào)>>: ').strip() 219 if trans_account.isdigit(): 220 if len(trans_account) == 10: 221 if trans_account in my_dict: 222 your_trans_money = input('請(qǐng)輸入你的轉(zhuǎn)賬金額>>: ').strip() 223 if your_trans_money.isdigit(): 224 money = int(your_trans_money) 225 with open('信用卡號(hào)和密碼.txt','r+',encoding = 'utf-8') as f1: 226 line1 = f1.read() 227 my_dict1 = eval(line1) 228 your_password = input('請(qǐng)輸入你的信用卡密碼>>: ').strip() 229 if your_password == my_dict1[trans_account]: 230 if money < my_dict[trans_account]: 231 my_dict[trans_account] = my_dict[trans_account] - money 232 my_dict[choice] = my_dict[choice] + money 233 print('轉(zhuǎn)賬成功'.center(20,'*')) 234 break 235 else: 236 print('密碼不正確,請(qǐng)重新輸入') 237 else: 238 print('輸入的金額不合法') 239 else: 240 print('輸入的賬號(hào)不存在') 241 else: 242 print('信用卡號(hào)的長(zhǎng)度不合法') 243 244 ''' 245 鎖定用戶 246 ''' 247 def lock_user(): 248 while True: 249 print('鎖定用戶'.center(20,'*')) 250 with open('用戶.txt','r+',encoding = 'utf-8') as f: 251 line= f.read() 252 my_lst = eval(line) 253 choice = input('是否進(jìn)行鎖定用戶(是或者否)>>: ').strip() 254 if choice == '否': 255 break 256 if choice == '是': 257 my_lock_user = input('請(qǐng)輸入想要鎖定的用戶名>>: ').strip() 258 for in_lst in my_lst: 259 if my_lock_user in in_lst: 260 in_lst[1] = '已鎖定' 261 print('%s用戶已經(jīng)鎖定'%(my_lock_user)) 262 263 264 else: 265 print('輸入的用戶名不存在') 266 267 ''' 268 創(chuàng)建用戶 269 ''' 270 def new_user(): 271 while True: 272 print('創(chuàng)建用戶'.center(20,'*')) 273 with open('用戶名和密碼.txt','r+',encoding = 'utf-8') as f: 274 line = f.read() 275 my_dic = eval(line) 276 for key in my_dic: 277 print('系統(tǒng)已經(jīng)有的用戶:%s'%(key)) 278 my_choice = input('請(qǐng)輸入你要?jiǎng)?chuàng)建的用戶名(選擇是或者否)>>: ').strip() 279 if my_choice == '否': 280 break 281 if my_choice == '是': 282 user_name = input('請(qǐng)輸入你想要?jiǎng)?chuàng)建的用戶名>>: ').strip() 283 user_password = input('請(qǐng)輸入創(chuàng)建用戶的密碼>>: ').strip() 284 if user_name not in my_dic: 285 if len(user_name) > 0 and len(user_password) > 0: 286 my_dic[user_name] = user_password 287 print('創(chuàng)建%s成功'%(user_name)) 288 else: 289 print('輸入的用戶或者密碼不能為空!') 290 else: 291 print('輸入的用戶已經(jīng)存在') 292 ''' 293 主函數(shù)接口 294 ''' 295 def main(): 296 print('購(gòu)物商城ATM系統(tǒng)'.center(20,'*')) 297 while True: 298 print('歡迎來(lái)到ATM購(gòu)物系統(tǒng)'.center(20,'*')) 299 choice = input('請(qǐng)輸入選擇的ID號(hào)>>: ').strip() 300 if choice == 'q': 301 print('再見'.center(20,'*')) 302 exit() 303 if choice.isdigit(): 304 choice = int(choice) 305 if choice >= 1 and choice <= 4: 306 while True: 307 if choice == 1: 308 print('歡迎來(lái)到信用卡中心'.center(20,'*')) 309 credit_choice = input('請(qǐng)輸入信用卡板塊號(hào)>>: ').strip() 310 if credit_choice.isdigit(): 311 credit_choice = int(credit_choice) 312 if credit_choice >= 1 and credit_choice <= 2: 313 if credit_choice == 1: 314 credit_data()#信用卡信息 315 break 316 elif credit_choice == 2: 317 my_trans()#信用卡轉(zhuǎn)賬信息 318 break 319 elif choice == 2: 320 print('歡迎來(lái)到購(gòu)物中心'.center(20,'*')) 321 shopping_choice = input('請(qǐng)選擇購(gòu)物板塊>>: ').strip() 322 if shopping_choice.isdigit(): 323 shopping_choice = int(shopping_choice) 324 if shopping_choice >= 1 and shopping_choice <= 3: 325 while True: 326 if shopping_choice == 1: 327 shop_list()#購(gòu)物商城和購(gòu)物車 328 break 329 elif shopping_choice == 2: 330 my_delete_cart()#清空購(gòu)物車板塊 331 break 332 elif shopping_choice == 3: 333 my_pay()#購(gòu)物車結(jié)算版塊 334 break 335 else: 336 print('請(qǐng)輸入正確的板塊號(hào)') 337 elif choice == 3: 338 print('歡迎來(lái)到用戶管理中心'.center(20,'*')) 339 admin_choice = input('請(qǐng)輸入選擇的板塊號(hào)>>: ').strip() 340 if admin_choice.isdigit(): 341 admin_choice = int(admin_choice) 342 if admin_choice >= 1 and admin_choice <= 3: 343 while True: 344 if admin_choice == 1: 345 user_auth()#用戶認(rèn)證板塊 346 break 347 elif admin_choice == 2: 348 credit_auth()#信用卡認(rèn)證 349 break 350 elif admin_choice == 3: 351 admin_auth()#管理員認(rèn)證 352 break 353 elif choice == 4: 354 print('歡迎來(lái)到創(chuàng)建用戶板塊'.center(20,'*')) 355 user_choice = input('請(qǐng)輸入選擇的板塊號(hào)>>: ').strip() 356 if user_choice.isdigit(): 357 user_choice = int(user_choice) 358 if user_choice >= 1 and user_choice <= 2: 359 while True: 360 if user_choice == 1: 361 lock_user()#鎖定用戶板塊 362 break 363 elif user_choice == 2: 364 new_user()#創(chuàng)建用戶板塊 365 break 366 367 else: 368 print('輸入的板塊號(hào)不正確') 369 break 370 371 372 main() View Code
模擬實(shí)現(xiàn)一個(gè)ATM+購(gòu)物商城程序
1.額度1500或者自定義
2.實(shí)現(xiàn)購(gòu)物商城,買東西加入購(gòu)物車,調(diào)用信用卡接口
3.可以提現(xiàn),手續(xù)費(fèi)5%
4.支持賬戶登錄
5.支持賬戶間轉(zhuǎn)賬
6.記錄每日日常消費(fèi)流水
7.提供還款接口
8.ATM記錄操作日志
9.提供管理接口,包括添加賬戶,用戶額度,凍結(jié)賬戶等
10.用戶認(rèn)證用裝飾 1 #Author wangmengzhu 2 ''' 3 用戶認(rèn)證,確認(rèn)是用戶登錄,判斷用戶登錄的用戶名和密碼是否正確,判斷用戶認(rèn)證的長(zhǎng)度是否為0,使用裝飾器 4 用戶登錄認(rèn)證,信用卡登錄認(rèn)證,管理員登錄認(rèn)證 5 ''' 6 import time,os 7 def auth(auth_type): 8 ''' 9 用戶的認(rèn)證信息 10 ''' 11 def my_wrapper(func): 12 if auth_type == 'user_auth': 13 def wrpper(*args,**kwargs): 14 name = input('請(qǐng)輸入你的用戶名>>: ').strip() 15 password = input('請(qǐng)輸入你的密碼>>: ').strip() 16 if len(name) > 0: 17 with open('用戶名和密碼.txt','r',encoding = 'utf-8') as f: 18 line = f.read() 19 my_dic = eval(line) 20 if name in my_dic and password == my_dic[name]: 21 print('%s歡迎登陸'%(name)) 22 func(*args,**kwargs) 23 else: 24 print('%s認(rèn)證失敗'%(name)) 25 else: 26 print('輸入的用戶名不能為空') 27 return wrpper 28 elif auth_type == 'credit_auth': 29 def wrpper(*args, **kwargs): 30 credit_number = input('請(qǐng)輸入你的信用卡號(hào)>>: ').strip() 31 credit_password = input('請(qǐng)輸入你的信用卡密碼>>: ').strip() 32 if len(credit_number) == 10: 33 with open('信用卡號(hào)和密碼.txt','r',encoding = 'utf-8') as f: 34 line = f.read() 35 my_dic = eval(line) 36 if credit_number in my_dic and credit_password == my_dic[credit_number]: 37 print('認(rèn)證成功,歡迎登陸') 38 func(*args, **kwargs) 39 else: 40 print('認(rèn)證不成功') 41 else: 42 print('輸入的信用卡號(hào)的長(zhǎng)度不對(duì)') 43 return wrpper 44 elif auth_type == 'admin_auth': 45 def wrpper(*args, **kwargs): 46 admin_name = input('請(qǐng)輸入你的管理員用戶名>>: ').strip() 47 admin_password = input('請(qǐng)輸入你的管理員密碼>>: ').strip() 48 if len(admin_name) > 0: 49 with open('管理員用戶名和密碼.txt', 'r', encoding='utf-8') as f: 50 line = f.read() 51 my_dic = eval(line) 52 if admin_name in my_dic and admin_password== my_dic[admin_name]: 53 print('%s歡迎登陸' % (admin_name)) 54 func(*args, **kwargs) 55 with open('日志模塊.txt', 'a+', encoding='utf-8') as f: 56 f.write('%s %s run' % (time.strftime('%Y-%m-%d %X'), func.__name__)) 57 else: 58 print('%s認(rèn)證失敗' % (admin_name)) 59 else: 60 print('輸入的用戶名不能為空') 61 62 return wrpper 63 return my_wrapper 64 @auth(auth_type = 'user_auth') 65 def user_auth(): 66 print('用戶登錄認(rèn)證'.center(20,'*')) 67 @auth(auth_type = 'credit_auth') 68 def credit_auth(): 69 print('信用卡認(rèn)證'.center(20,'*')) 70 @auth(auth_type = 'admin_auth') 71 def admin_auth(): 72 print('管理員認(rèn)證'.center(20,'*')) 73 74 ''' 75 購(gòu)物商城和購(gòu)物車 76 ''' 77 def shop_list(): 78 my_shop_list = [] 79 my_buy_list = [] 80 with open('商品列表.txt','r+',encoding = 'utf-8') as f: 81 for item in f: 82 item.split(',') 83 my_shop_list.append(item) 84 print('目前商品所在的信息'.center(20, '*')) 85 for j in my_shop_list: 86 print(j,end = '') 87 print('\n',end = '') 88 while True: 89 my_choice = input('請(qǐng)輸入想要購(gòu)買的商品序號(hào)>>: ').strip() 90 if my_choice.isdigit(): 91 my_choice = int(my_choice) 92 if my_choice < len(my_shop_list) and my_choice > 0: 93 my_buy = my_shop_list[my_choice] 94 print(my_buy) 95 with open('我的購(gòu)物列表.txt', 'a+', encoding='utf-8') as f: 96 f.write(my_buy) 97 break 98 else: 99 print('輸入的商品編號(hào)錯(cuò)誤') 100 continue 101 else: 102 print('輸入的數(shù)字不合法') 103 continue 104 105 106 ''' 107 清空購(gòu)物車 108 ''' 109 def my_delete_cart(): 110 while True: 111 my_cart = []#我的購(gòu)物車 112 with open('我的購(gòu)物列表.txt','r+',encoding = 'utf-8') as f: 113 for line in f: 114 my_cart.append(line) 115 if my_cart != []: 116 my_choice = input('是否清空購(gòu)物車,回答YES或者NO>>: ').strip() 117 print('我的購(gòu)物車中的商品'.center(20,'*')) 118 for j in my_cart: 119 print(j,end = '') 120 if my_choice =='YES': 121 with open('我的購(gòu)物列表.txt','w',encoding = 'utf-8') as f: 122 pass 123 print('購(gòu)物車已經(jīng)清空') 124 elif my_choice == 'NO': 125 print('請(qǐng)繼續(xù)購(gòu)物吧!') 126 else: 127 print('輸入不正確,請(qǐng)重新輸入') 128 else: 129 print('購(gòu)物車?yán)镞呥€沒有商品') 130 break 131 132 133 134 ''' 135 購(gòu)物車結(jié)算 136 ''' 137 def my_pay(): 138 while True: 139 print('購(gòu)物結(jié)算'.center(20,'*')) 140 my_cart = [] 141 my_trans = [] 142 with open('我的購(gòu)物列表.txt','r+',encoding = 'utf-8') as f: 143 for line in f: 144 my_cart.append(line) 145 if my_cart != []: 146 print('購(gòu)物車清單'.center(20,'*')) 147 for j in my_cart: 148 my_new = j.split(',') 149 my_trans.append(my_new) 150 money = sum([int(i[2]) for i in my_trans]) 151 print(money) 152 else: 153 print('你還沒有消費(fèi)過(guò),快去買點(diǎn)你心儀的商品吧!') 154 break 155 my_choice = input('是否進(jìn)行結(jié)賬[合計(jì)%s人民幣](請(qǐng)回答Y或者N)>>: '%(money)).strip() 156 if my_choice == 'N': 157 break 158 elif my_choice == 'Y': 159 credit_auth()#調(diào)用信用卡接口認(rèn)證 160 my_credit_num = input('請(qǐng)輸入你的信用卡號(hào)').strip() 161 with open('信用卡號(hào)和密碼.txt','r+',encoding = 'utf-8') as f: 162 line = f.read() 163 my_dic = eval(line) 164 if my_credit_num not in my_dic: 165 print('認(rèn)證的信用卡號(hào)不存在,請(qǐng)重新輸入') 166 else: 167 with open('信用卡號(hào)和資金.txt','r+',encoding = 'utf-8') as f1: 168 line1 = f1.read() 169 my_dic1 = eval(line1) 170 your_credit = input('請(qǐng)輸入你的信用卡號(hào)>>: ').strip() 171 your_password = input('請(qǐng)輸入你的密碼>>: ').strip() 172 if your_credit in my_dic1 and your_password == my_dic1[your_credit]: 173 print('你的賬戶總共的資金為%s'%(my_dic1[your_credit])) 174 your_limit = my_dic1[your_credit] - money 175 if your_limit >= 0: 176 my_dic1[your_credit] = your_limit 177 print('支付成功,當(dāng)前信用卡余額為%s'%(your_limit)) 178 else: 179 print('余額不足,請(qǐng)充值') 180 else: 181 print('輸入的密碼錯(cuò)誤,請(qǐng)重新輸入') 182 continue 183 ''' 184 信用卡信息 185 ''' 186 def credit_data(): 187 while True: 188 with open('信用卡號(hào)和資金.txt','r+',encoding = 'utf-8') as f: 189 my_msg = f.read() 190 my_dic = eval(my_msg) 191 your_choice = input('請(qǐng)輸入要查看信息的信用卡號(hào)>>: ').strip() 192 if your_choice in my_dic: 193 print('我的信用卡信息'.center(20,'*')) 194 print('持卡人信用卡號(hào)%s\n持卡人余額%s'%(your_choice,my_dic[your_choice])) 195 else: 196 print('你輸入的信用卡號(hào)不存在,請(qǐng)重新輸入') 197 continue 198 choice = input('是否選擇退出(是或者否)>>: ').strip() 199 if choice == '是': 200 print('歡迎下次查詢') 201 break 202 else: 203 continue 204 205 206 207 ''' 208 信用卡轉(zhuǎn)賬 209 ''' 210 def my_trans(): 211 while True: 212 with open('信用卡號(hào)和資金.txt','r+',encoding = 'utf-8') as f: 213 line = f.read() 214 my_dict = eval(line) 215 choice = input('請(qǐng)輸入信用卡號(hào)>>: ').strip() 216 if choice in my_dict: 217 current_money = my_dict[choice] 218 trans_account = input('請(qǐng)輸入你要轉(zhuǎn)賬的賬號(hào)>>: ').strip() 219 if trans_account.isdigit(): 220 if len(trans_account) == 10: 221 if trans_account in my_dict: 222 your_trans_money = input('請(qǐng)輸入你的轉(zhuǎn)賬金額>>: ').strip() 223 if your_trans_money.isdigit(): 224 money = int(your_trans_money) 225 with open('信用卡號(hào)和密碼.txt','r+',encoding = 'utf-8') as f1: 226 line1 = f1.read() 227 my_dict1 = eval(line1) 228 your_password = input('請(qǐng)輸入你的信用卡密碼>>: ').strip() 229 if your_password == my_dict1[trans_account]: 230 if money < my_dict[trans_account]: 231 my_dict[trans_account] = my_dict[trans_account] - money 232 my_dict[choice] = my_dict[choice] + money 233 print('轉(zhuǎn)賬成功'.center(20,'*')) 234 break 235 else: 236 print('密碼不正確,請(qǐng)重新輸入') 237 else: 238 print('輸入的金額不合法') 239 else: 240 print('輸入的賬號(hào)不存在') 241 else: 242 print('信用卡號(hào)的長(zhǎng)度不合法') 243 244 ''' 245 鎖定用戶 246 ''' 247 def lock_user(): 248 while True: 249 print('鎖定用戶'.center(20,'*')) 250 with open('用戶.txt','r+',encoding = 'utf-8') as f: 251 line= f.read() 252 my_lst = eval(line) 253 choice = input('是否進(jìn)行鎖定用戶(是或者否)>>: ').strip() 254 if choice == '否': 255 break 256 if choice == '是': 257 my_lock_user = input('請(qǐng)輸入想要鎖定的用戶名>>: ').strip() 258 for in_lst in my_lst: 259 if my_lock_user in in_lst: 260 in_lst[1] = '已鎖定' 261 print('%s用戶已經(jīng)鎖定'%(my_lock_user)) 262 263 264 else: 265 print('輸入的用戶名不存在') 266 267 ''' 268 創(chuàng)建用戶 269 ''' 270 def new_user(): 271 while True: 272 print('創(chuàng)建用戶'.center(20,'*')) 273 with open('用戶名和密碼.txt','r+',encoding = 'utf-8') as f: 274 line = f.read() 275 my_dic = eval(line) 276 for key in my_dic: 277 print('系統(tǒng)已經(jīng)有的用戶:%s'%(key)) 278 my_choice = input('請(qǐng)輸入你要?jiǎng)?chuàng)建的用戶名(選擇是或者否)>>: ').strip() 279 if my_choice == '否': 280 break 281 if my_choice == '是': 282 user_name = input('請(qǐng)輸入你想要?jiǎng)?chuàng)建的用戶名>>: ').strip() 283 user_password = input('請(qǐng)輸入創(chuàng)建用戶的密碼>>: ').strip() 284 if user_name not in my_dic: 285 if len(user_name) > 0 and len(user_password) > 0: 286 my_dic[user_name] = user_password 287 print('創(chuàng)建%s成功'%(user_name)) 288 else: 289 print('輸入的用戶或者密碼不能為空!') 290 else: 291 print('輸入的用戶已經(jīng)存在') 292 ''' 293 主函數(shù)接口 294 ''' 295 def main(): 296 print('購(gòu)物商城ATM系統(tǒng)'.center(20,'*')) 297 while True: 298 print('歡迎來(lái)到ATM購(gòu)物系統(tǒng)'.center(20,'*')) 299 choice = input('請(qǐng)輸入選擇的ID號(hào)>>: ').strip() 300 if choice == 'q': 301 print('再見'.center(20,'*')) 302 exit() 303 if choice.isdigit(): 304 choice = int(choice) 305 if choice >= 1 and choice <= 4: 306 while True: 307 if choice == 1: 308 print('歡迎來(lái)到信用卡中心'.center(20,'*')) 309 credit_choice = input('請(qǐng)輸入信用卡板塊號(hào)>>: ').strip() 310 if credit_choice.isdigit(): 311 credit_choice = int(credit_choice) 312 if credit_choice >= 1 and credit_choice <= 2: 313 if credit_choice == 1: 314 credit_data()#信用卡信息 315 break 316 elif credit_choice == 2: 317 my_trans()#信用卡轉(zhuǎn)賬信息 318 break 319 elif choice == 2: 320 print('歡迎來(lái)到購(gòu)物中心'.center(20,'*')) 321 shopping_choice = input('請(qǐng)選擇購(gòu)物板塊>>: ').strip() 322 if shopping_choice.isdigit(): 323 shopping_choice = int(shopping_choice) 324 if shopping_choice >= 1 and shopping_choice <= 3: 325 while True: 326 if shopping_choice == 1: 327 shop_list()#購(gòu)物商城和購(gòu)物車 328 break 329 elif shopping_choice == 2: 330 my_delete_cart()#清空購(gòu)物車板塊 331 break 332 elif shopping_choice == 3: 333 my_pay()#購(gòu)物車結(jié)算版塊 334 break 335 else: 336 print('請(qǐng)輸入正確的板塊號(hào)') 337 elif choice == 3: 338 print('歡迎來(lái)到用戶管理中心'.center(20,'*')) 339 admin_choice = input('請(qǐng)輸入選擇的板塊號(hào)>>: ').strip() 340 if admin_choice.isdigit(): 341 admin_choice = int(admin_choice) 342 if admin_choice >= 1 and admin_choice <= 3: 343 while True: 344 if admin_choice == 1: 345 user_auth()#用戶認(rèn)證板塊 346 break 347 elif admin_choice == 2: 348 credit_auth()#信用卡認(rèn)證 349 break 350 elif admin_choice == 3: 351 admin_auth()#管理員認(rèn)證 352 break 353 elif choice == 4: 354 print('歡迎來(lái)到創(chuàng)建用戶板塊'.center(20,'*')) 355 user_choice = input('請(qǐng)輸入選擇的板塊號(hào)>>: ').strip() 356 if user_choice.isdigit(): 357 user_choice = int(user_choice) 358 if user_choice >= 1 and user_choice <= 2: 359 while True: 360 if user_choice == 1: 361 lock_user()#鎖定用戶板塊 362 break 363 elif user_choice == 2: 364 new_user()#創(chuàng)建用戶板塊 365 break 366 367 else: 368 print('輸入的板塊號(hào)不正確') 369 break 370 371 372 main() View Code
?
轉(zhuǎn)載于:https://www.cnblogs.com/wangmengzhu/p/7244665.html
總結(jié)
以上是生活随笔為你收集整理的Python__模拟实现一个ATM+购物商城程序的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: ios 之 autoresizing小解
- 下一篇: dede后台栏目管理文章统计数量和实际文