到目前为止,我已经“制作”了一个ATM程序,它可以保存到一个文件中并且可以记住东西等等。现在我需要尝试制作它以便它可以有一个引脚保护系统,我该如何制作呢?我会把它放在我的代码中?我需要再次保存到文件吗?请帮忙
users = {}
userInput = 0
money = 0
with open("N:\ATM.txt") as f:
for line in f:
(key, val) = line.split()
users[key] = val
print "Welcome to the ATM"
check = raw_input("Are you a new user?: ").lower()
if check == "yes":
user= raw_input("Hi, new user, what is your name? ")
users[user] = 0
else:
user = raw_input("Please enter your name to log: ").lower()
if user in users:
print "Welcome Back" , user
money = float(users[user])
while userInput != "d":
with open("N:\ATM.txt") as f:
userInput = raw_input("\n what would you like to do?\n\n (1)Check balance\n (2)Insert funds\n" +
" (3)Make a withdrawl\n (4)Exit the ATM\n" ).lower()
if userInput == "1":
print "your balance is", "£" , money
elif userInput == "2":
mon = float(raw_input("Enter the amount of money you want to add "))
money = money + mon
elif userInput == "3":
withdraw = float(raw_input("Enter the amount of money you want to withdraw"))
money = money - withdraw
elif userInput == "4":
users[user] = money
print "Bye, thank you for using the ATM"
exit()
with open("N:\ATM.txt", 'w') as f:
for key, value in users.items():
f.write('{} {}\n'.format(key, value))