python實現atm機的部分功能

來源:互聯網
上載者:User

標籤:python

環境:python2.7

缺陷:錢不變,待完善


# -*- coding: utf-8 -*-user_name = "C:\Users\95112\Desktop\ATM\username" #定義使用者名稱和密碼的位置goods     = "C:\Users\95112\Desktop\ATM\goods"  #定義商品列表的的位置#登入def login():global aglobal salaryusername=[]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相對應的密碼salary = money[username.index(UserName)]  #取出賬戶中相對應的錢if PassWord == username_passwd:a = 1 #登入成功的標誌print "Login successful"print "You still have %s of the balance" % moneyelse:a = 0print "password error"else:a = 0print "your username error"return areturn salary#購物def shopping(salary):global sproducts=[]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 productsfor 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()#去除空格,格式化輸出。#退出迴圈if F_choice == "exit":breakif F_choice in products:product_price = price[products.index(F_choice)] #取出產品價格print "+---------------------------------+"print u"你要購買的商品以及價格:",F_choice,product_priceprint u"商品正在加入購物列表,請稍等"if salary > product_price:shop_list.append(F_choice)salary = salary - product_priceprint "+---------------------------------+"print u"你已經成功購買了%s" % F_choiceprint u"你的餘額還有:", salaryprint u"你已經購買的商品有:", shop_listprint "+---------------------------------+"else:passelse:print u"你輸入的商品不在商品列表裡,請重新輸入!"return salary#轉賬或者提現def Transfer_accounts(salary):print u"每次轉賬和提現收取百分之5的服務費."inputs = int(raw_input("please input you should how much money:"))SS = inputs*0.05zong = inputs + SSif ( salary < zong or salary < input):print u"餘額不足"else:salary = salary - zongreturn salary#菜單def menu(salary):    print u"""Welcome to use ATM automatic teller machine            If the machine failure please contact ATM\t """    while True:    print "\t(1) shop"    print "\t(2) Transfer accounts"    print "\t(3) quit"        choices = raw_input("Please choices:").strip()        if len(choices) == 0:        continue        if choices == ‘1‘:        shopping(salary)    elif choices == ‘2‘:    Transfer_accounts(salary)        else:            print "Please pay attention to the property security"            exit()if __name__ == ‘__main__‘:login()if a == 1:menu(salary)else:pass

650) this.width=650;" src="https://s4.51cto.com/wyfs02/M00/9C/61/wKioL1lvgfSCMn1oAAQF1aT1ixQ444.png" title="打賞.png" alt="wKioL1lvgfSCMn1oAAQF1aT1ixQ444.png" />

本文出自 “天道酬勤” 部落格,請務必保留此出處http://taindaochouqin.blog.51cto.com/12995943/1949133

python實現atm機的部分功能

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.