I would like to expand my account management by allowing customers to open a new account with their name and account balance. The account number should be generated automatically (consecutive).
I would also like to add the following:
- It should not be possible to overdraw the account.
- It should no longer be possible to deposit or withdraw a negative amount.
Unfortunately I can't get any further here.
This is how my account.txt file looks like:
1, Max Mustermann, 1000.0
2, Nora Mustermann, 790.0
3, Tomas Mustermann, 400.0
This my coding:
data = {}
with open("Account.txt") as f:
print("Which account do you want to use?")
for folder in f:
list = folder.split(",")
account_number = int(list[0])
name = list[1]
credit = list[2]
data[account_number] = list[1:]
print(f" [{account_number}] {name}")
print(" [+] Create new account")
print(" [0] End")
input_first = int(input(" Your input: "))
if input_first == 0:
print("Thank you and see you again")
exit()
elif input_first == '+':
print("new account")
#From here I get no further, how to use "+" in a input?
while input_first in data:
credit2 = data[input_first][1]
name2 = data[input_first][0]
with open('Account.txt', 'r') as file:
filedata = file.read()
print("\n[1] Deposit\n[2] Withdraw\n")
execution = int(input(" Your Input: "))
#How can I overdraw my account and make it impossible to deposit or withdraw a negative amount?
if execution == 1:
deposit = float(input(" Your deposit: "))
amount_e = float(credit2) + float(deposit)
print(f" The account balance of account{name2} is {amount_e:.2f} $")
filedata = filedata.replace(str(credit2), str(amount_e) + '\n')
elif execution == 2:
payout = float(input(" Your pay out: "))
amount_a = float(credit2) - float(payout)
filedata = filedata.replace(str(credit2), str(amount_a) + '\n')
print(f" The account balance of account{name2} is {amount_a:.2f} $")
with open('Account.txt', 'w') as file:
file.write(filedata)