您好,登錄后才能下訂單哦!
環(huán)境:python2.7
可以進(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相對應(yīng)的密碼 salary = money[username.index(UserName)] #取出賬戶中相對應(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'請從以下商品中挑選一個或者幾個購買:' 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)品價格 print "+---------------------------------+" print u"你要購買的商品以及價格:",F_choice,product_price print u"商品正在加入購物列表,請稍等" 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"你輸入的商品不在商品列表里,請重新輸入!" return salary #轉(zhuǎn)賬或者提現(xiàn) def Transfer_accounts(): global salary print u"每次轉(zhuǎn)賬和提現(xiàn)收取百分之5的服務(wù)費." 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ù)費%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
運行結(jié)果:
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。