Python's ATM (fifth day)

Source: Internet
Author: User

Introduction to ATM Programs:

1, Login login.py

2, take the present cash.py

3. Repayment cashin.py

4, log query query.py

ATM Main Program Menu

#!/usr/bin/env python
Import Sys,pickle
Import Pickle
Import Account,login,cash,cashin,query



def main (name):
While True:
Print "' \033[1m
Main Menu:
1.cash
2.cashin
3.query
4.quit
\033[0m ""
Try
One=int (Raw_input (' Choice one,input the num 1/2/3/4/5: '). Strip ())
if one = = 1:
Cash.cash (name)
elif one = = 2:
Cashin.cashin (name)
elif one = = 3:
Query.query (name)
elif one = = 4:
Sys.exit ()
Else
Print "Only accept 1/2/3/4"
Continue

Except ValueError:
Print "Only accept 1/2/3/4"
Continue



Name=login.login ()
Main (name)


login.py

Import Sys
Import Pickle
Import time


def login ():
Account_file=file (' account.pkl ', ' RB ')
Account_info=pickle.load (Account_file)
Account_file.close ()
A=0
Global Name
While True:
Name=raw_input ("Input your Name:"). Strip ()
If Account_info.has_key (name):
If account_info[name][3] = = "0":
A=0
While a<3:
Pwd=raw_input ("Input your Password:"). Strip ()
if pwd = = Account_info[name][0]:
Now=time.strftime ('%y-%m-%d%h:%m:%s ', Time.localtime (Time.time ()))
F=file (' Login.log ', ' a ')
F.write ("[%s]%s login in\n"% (now,name))
F.flush ()
F.close ()
return name
Else
Print "Error password"
A+=1
Continue
Else
Account_info[name][3]=1
Account_file=file (' account.pkl ', ' WB ')
Pickle.dump (Account_info,account_file)
Account_file.close ()

Now=time.strftime ('%y-%m-%d%h:%m:%s ', Time.localtime (Time.time ()))
F=file (' Login.log ', ' a ')
F.write ("[%s]%s locked\n"% (now,name))
F.flush ()
F.close ()
Print "has input wrong pwd 3 times!!"
Sys.exit ()
Else
Print "The user%s has been lock!" %name
Sys.exit ()
Else
Print "Error name"
Continue


ACCOUNT.PKL account Information User name: admin password 123 user name admin2 password 123
(dp0
S ' admin '
P1
(LP2
S ' 123 '
P3
As ' 15000 '
P4
aF8070.0
As ' 0 '
P5
The ' admin2 '
P6
(LP7
G3
Ag4
aF14990.0
Ag5
As.
account.py  

Import Pickle
Import OS


If Os.path.exists (' Account.pkl '):
Pass
Else
account_info={
' Administrator ': [' 123 ', ' 15000 ', ' 15000 ', ' 0 ']
}
Account_file=file (' account.pkl ', ' WB ')
Pickle.dump (Account_info,account_file)
Account_file.close ()



Cash Withdrawal cash

Import Pickle
Import time


def cash (name):
Account_file=file (' account.pkl ', ' RB ')
Account_info=pickle.load (Account_file)
Account_file.close ()

Try
Get_num=int (raw_input (' input the number you want to get (100*n): '))
If get_num%100 = = 0:
If Get_num > account_info[name][2]:
Print "Sorry,not enough money,you just less $%s"%account_info[name][2]
Else
poundage=get_num*0.05
Account_info[name][2]=int (account_info[name][2])-get_num-poundage
Account_file=file (' account.pkl ', ' WB ')
Pickle.dump (Account_info,account_file)
Account_file.close ()

Now=time.strftime ('%y-%m-%d%h:%m:%s ', Time.localtime (Time.time ()))
Record= "cash%s"%get_num
F=file (' User.log ', ' a ')
F.write ("%s\t%s\t%s\t$%d\t$%.2f\n"% (now,name,record,get_num,poundage))
F.flush ()
F.close ()
Print "\033[1;31;40mcash $%s success,less $%s\033[0m"% (str (get_num), str (account_info[name][2]))

Else
Print "Sorry,only the number 100*n!"

Except ValueError:
Print "Sorry,only the number 100*n!"




      

Repayment Cashin


Import Pickle
Import time


def cash (name):
Account_file=file (' account.pkl ', ' RB ')
Account_info=pickle.load (Account_file)
Account_file.close ()

Try
Get_num=int (raw_input (' input the number you want to get (100*n): '))
If get_num%100 = = 0:
If Get_num > account_info[name][2]:
Print "Sorry,not enough money,you just less $%s"%account_info[name][2]
Else
poundage=get_num*0.05
Account_info[name][2]=int (account_info[name][2])-get_num-poundage
Account_file=file (' account.pkl ', ' WB ')
Pickle.dump (Account_info,account_file)
Account_file.close ()

Now=time.strftime ('%y-%m-%d%h:%m:%s ', Time.localtime (Time.time ()))
Record= "cash%s"%get_num
F=file (' User.log ', ' a ')
F.write ("%s\t%s\t%s\t$%d\t$%.2f\n"% (now,name,record,get_num,poundage))
F.flush ()
F.close ()
Print "\033[1;31;40mcash $%s success,less $%s\033[0m"% (str (get_num), str (account_info[name][2]))

Else
Print "Sorry,only the number 100*n!"

Except ValueError:
Print "Sorry,only the number 100*n!"


Query query.py


Import Pickle
Import time

def query (name):
Account_file=file (' account.pkl ', ' RB ')
Account_info=pickle.load (Account_file)
Account_file.close ()

Mm=raw_input (' Input the Month want to query (2016-01): '). Strip ()
If Len (mm) = = 0:
Mm=time.strftime ('%y-%m ', Time.localtime (Time.time ()))
If Len (mm) = = 7:
Print "user:%s\tlimit:$%s\tless:$%.2f"% (name,account_info[name][1],account_info[name][2])
Print "Month%s Bill:"%mm
Print "\033[1mtime\t\t\tname\trecord\tmoney\tpoundage\033[0m"
F=file (' User.log ')
For I in F.readlines ():
A=i.split ()
If name = = A[2] and mm in a[0]:
Print "%s%s\t%s\t%s\t%s\t%s\n"% (A[0],a[1],a[2],a[3],a[4],a[5]),
F.close ()
Else
print "Invalid format"



Log file User.log
Time          Name   Record money  poundage
2016-02-27 16:29:46 Admin Cash100 $ $5.00
2016-02-27 16:29:48 Admin Cash100 $ $5.00
2016-02-27 16:29:50 Admin Cash200 $ $10.00
2016-02-27 16:29:52 admin Cash300 $15.00
2016-02-27 16:30:14 admin Cashin $ A
2016-02-27 16:30:18 admin Cashin




Python's ATM (fifth day)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.