Get the App
SLTechnology News&Howtos  ›  Servers  › 

Implementation of simple ATM with python

Shulou Source: shulou.com Published: 2022-06-02 15:36:03 10月01日 Update

Environment: Python 2.7

can further improve

# -*- coding: utf-8-*-print u"+===================================================+"print u"+======================================== = "C:\Users\95112\Desktop\ATM\goods" #Define the location of the goods list salary = 0#Login 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)] #Remove password corresponding to username salary = money[username.index(UserName)] #Remove money from your account if PassWord == username_passwd: a = 1 #Sign of successful login 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'Please choose one or more of the following items to buy: print products for i in range(0,len(products)): if (salary>=price[i]): print products[i],price[i] print "+---------------------------------+" print u"Enter exit to exit the purchase" choice = raw_input("please choice a shop to buy:") F_choice = choice.strip()#Strips spaces and formats output. #exit loop if F_choice == "exit": break if F_choice in products: product_price = price[products.index(F_choice)] #Take out product price print "+---------------------------------+" print u"The item you want to buy and the price: ",F_choice,product_price print u"Item is being added to shopping list, please wait" if salary > product_price: shop_list.append(F_choice) salary = salary - product_price print "+---------------------------------+" print u"You have successfully purchased %s" % F_choice print u"Your balance is still: ", salary print u"The items you have purchased are: ", shop_list print "+---------------------------------+" else: pass else: print u"The product you entered is not in the product list, please re-enter! " def Transfer_accounts(): global salary print u"There is a 5% service charge for each transfer and withdrawal. " 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"Insufficient balance" else: salary = salary - zong print "+------------------------------+" print u"successful transfer %s" % inputs print u"Deduct commission %s" % SS print "+------------------------------+" def check_the_balance(): global salary print "+---------------------------+" print u"You have %s" % salary print "+---------------------------+"#Menu 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) Shopping" print u"\t(2) Transfer" print u"\t(3) Query Balance" print u"\t(4) Exit" 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

Run Results:

Tags: Merchandise balance transfer success Shopping input Price location password query Login Tiandao reward Product author Tiandao formalities handling fee Service charge Mark format Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno vpn Xiaomi Shulou Technology Docker