Вот мой код:-
f= open("Passes.py", "a+")
m=open("money.py","a+")
passes= {}
init={}
initial=0
import time
wait=time.sleep(0.5)
print "Welcome to the virtual banking system"
wait
user=raw_input("Would you like to create a new account? 'Y/N'").lower()
if user== "y":
new_user= raw_input("Create a username:")
new_pass= raw_input("Create a password:")
p= passes[new_user]= new_user + ":" + new_pass
f.write("\n"+p)
ask=raw_input("Would you like to sign into your account? 'Y/N'").lower()
if ask=="y":
user_in=raw_input("Enter your username:")
if user_in==new_user:
pass_in=raw_input("Enter your password:")
if pass_in==new_pass:
running=True
while running:
print "Welcome to your account" + " " + new_user
useropt=raw_input("Would you like to view your balance- enter 1, deposit money- enter 2 or withdraw money- enter 3:")
if useropt=="1":
print "Your balance is:", initial
m.write("\n"+str(initial))
if useropt=="2":
m.close()
u=open("money.py","r+")
amountdep= int(raw_input("How much money would you like to deposit?:"))
initial+=amountdep
print "Thanks. Your new balance is:", initial
u.write(str(initial)+"\n")
if useropt=="3":
m.close()
r=open("money.py","r+")
amountwith=int(raw_input("How much would you like to withdraw?:"))
initial-=amountwith
if initial>=0:
print "Your balance is:", initial
r.write(str(initial)+"\n")
else:
print "Sorry, this amount cannot be withdrawn. Balance cannot be less than 0"
cont = raw_input("Would you like to do another operation? 'Y/N'").lower()
running = cont == "y"
else:
print "Password not valid"
else:
print "Username does not exist"
else:
print "Thanks for using the virtual bank."
else:
user2=raw_input("Do you have an existing account? 'Y/N'").lower()
if user2=="y":
existing_user=raw_input("Enter your username:")
exisitng_pass=raw_input("Enter your password:")
for passwords in f:
if passwords==existing_user+":"+exisitng_pass:
run=True
while run:
print "Welcome to your account" + " " + existing_user
with open("money.py", "r") as m:
info= int(m.readline().strip())
useropt2=raw_input("Would you like to view your balance- enter 1, deposit money- enter 2 or withdraw money- enter 3:")
if useropt2=="1":
print "Your balance is:", info
if useropt2=="2":
amountdep= int(raw_input("How much money would you like to deposit?:"))
a=info+int(amountdep)
print "Your new balance is:", a
with open("money.py", "w") as m:
m.write(str(a))
if useropt2=="3":
amountwith=int(raw_input("How much would you like to withdraw?:"))
t=info-int(amountwith)
if t>=0:
print "Your balance is:", t
with open("money.py", "w") as m:
m.write(str(t))
else:
print "Sorry, this amount cannot be withdrawn. Balance cannot be less than 0"
restart = raw_input("Would you like to do another operation? 'Y/N'").lower()
run = restart == "y"
else:
print "Invalid username or password"
else:
print "Thanks for using the virtual bank."
У меня есть два файла, и один из них - «money.py». В этом файле хранится общая сумма денег на счете моего пользователя. Проблема, однако, в том, что в моей программе нет способа различить двух пользователей и их деньги, поскольку в них просто хранится целочисленное значение их общей суммы. Я также попытался написать имя пользователя, а затем сумму денег, но обнаружил, что это не работает, так как смешивает строки и целые числа. Есть ли способ отличить разных пользователей? Благодарю.