環(huán)境:python2.7
成都創(chuàng)新互聯(lián)是一家網(wǎng)站設(shè)計(jì)公司,集創(chuàng)意、互聯(lián)網(wǎng)應(yīng)用、軟件技術(shù)為一體的創(chuàng)意網(wǎng)站建設(shè)服務(wù)商,主營產(chǎn)品:自適應(yīng)網(wǎng)站建設(shè)、品牌網(wǎng)站建設(shè)、成都營銷網(wǎng)站建設(shè)。我們專注企業(yè)品牌在網(wǎng)站中的整體樹立,網(wǎng)絡(luò)互動(dòng)的體驗(yàn),以及在手機(jī)等移動(dòng)端的優(yōu)質(zhì)呈現(xiàn)。網(wǎng)站設(shè)計(jì)、成都網(wǎng)站制作、移動(dòng)互聯(lián)產(chǎn)品、網(wǎng)絡(luò)運(yùn)營、VI設(shè)計(jì)、云產(chǎn)品.運(yùn)維為核心業(yè)務(wù)。為用戶提供一站式解決方案,我們深知市場的競爭激烈,認(rèn)真對(duì)待每位客戶,為客戶提供賞析悅目的作品,網(wǎng)站的價(jià)值服務(wù)。
可以進(jìn)一步完善
# -*- coding: utf-8 -*- print u"+========================================+" print u"+=============2017年7月20日==============+" print u"+==============作者:天道酬勤============+" print u"+========================================+" user_name = "C:\Users\95112\Desktop\ATM\username" #定義用戶名和密碼的位置 goods = "C:\Users\95112\Desktop\ATM\goods" #定義商品列表的的位置 salary = 0 #登錄 def login(): global a global salary username=[] password=[] money =[] f = file(user_name) for line in f.readlines(): new_line = line.split() username.append(int(new_line[0])) password.append(int(new_line[1])) money.append(int(new_line[2])) UserName = int(raw_input("please input your username:")) if UserName in username: PassWord = int(raw_input("please input your password:")) username_passwd = password[username.index(UserName)] #取出username相對(duì)應(yīng)的密碼 salary = money[username.index(UserName)] #取出賬戶中相對(duì)應(yīng)的錢 if PassWord == username_passwd: a = 1 #登錄成功的標(biāo)志 print "Login successful" print "You still have %s of the balance" % money else: a = 0 print "password error" else: a = 0 print "your username error" return a return salary #購物 def shopping(): global salary products=[] price=[] shop_list= [] f = file(goods) for line in f.readlines(): new_line = line.split() products.append(new_line[0]) price.append(int(new_line[1])) while 1: print u'請(qǐng)從以下商品中挑選一個(gè)或者幾個(gè)購買:' print products for i in range(0,len(products)): if (salary>=price[i]): print products[i],price[i] print "+---------------------------------+" print u"輸入exit可以退出購買" choice = raw_input("please choice a shop to buy:") F_choice = choice.strip()#去除空格,格式化輸出。 #退出循環(huán) if F_choice == "exit": break if F_choice in products: product_price = price[products.index(F_choice)] #取出產(chǎn)品價(jià)格 print "+---------------------------------+" print u"你要購買的商品以及價(jià)格:",F_choice,product_price print u"商品正在加入購物列表,請(qǐng)稍等" if salary > product_price: shop_list.append(F_choice) salary = salary - product_price print "+---------------------------------+" print u"你已經(jīng)成功購買了%s" % F_choice print u"你的余額還有:", salary print u"你已經(jīng)購買的商品有:", shop_list print "+---------------------------------+" else: pass else: print u"你輸入的商品不在商品列表里,請(qǐng)重新輸入!" return salary #轉(zhuǎn)賬或者提現(xiàn) def Transfer_accounts(): global salary print u"每次轉(zhuǎn)賬和提現(xiàn)收取百分之5的服務(wù)費(fèi)." inputs = int(raw_input("please input you should how much money:")) SS = inputs*0.05 zong = inputs + SS if ( salary < zong or salary < inputs): print u"余額不足" else: salary = salary - zong print "+------------------------------+" print u"成功轉(zhuǎn)賬%s" % inputs print u"扣除手續(xù)費(fèi)%s" % SS print "+------------------------------+" return salary #查詢余額 def check_the_balance(): global salary print "+---------------------------+" print u"你的金額還有%s" % salary print "+---------------------------+" #菜單 def menu(): print u"""Welcome to use ATM automatic teller machine If the machine failure please contact ATM\t """ while True: print u"\t(1) 購物" print u"\t(2) 轉(zhuǎn)賬" print u"\t(3) 查詢余額" print u"\t(4) 退出" choices = raw_input("Please choices:").strip() if len(choices) == 0: continue if choices == '1': shopping() elif choices == '2': Transfer_accounts() elif choices == '3': check_the_balance() else: print "Please pay attention to the property security" exit() if __name__ == '__main__': login() if a == 1: menu() else: pass
運(yùn)行結(jié)果: