Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

199
Views
How to create a simple Account management using python?

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)
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

First of all, you shouldn't store user data in a txt file. It is not encrypted and it's prominent to data getting stolen. Might wanna look into a database like sqlite in case you want to store it locally or MySQL in case you want it to be stored in a server (I recommend SQlite to start off with). It is also way more intuitive to add, edit and remove elements this way than editing a plain txt file.

Regarding the negative values it's pretty easy. You just check if the value is not negative like this:

if execution == 1:
    deposit = 0
    #Don't proceed until a correct value is entered 
    while deposit < 0:
        try:
            deposit = float(input(" Your deposit: "))
        except TypeError:
            #For handling an error if a non-numeric value is entered
            pass
    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')

To stop a user from withdrawing a value higher than what's currently in its account you just check if the withdrawn value is bigger than the account's.

elif execution == 2:
    payout = 0
    #Keep asking for a value until the payout is less than the credit
    while payout > credit2:
        payout = float(input(" Your pay out: "))
        amount_a = float(credit2) - float(payout)
        # Print a message telling the user the reason
        if amount_a < 0:
           print("You don't have that much money in your account.")

    filedata = filedata.replace(str(credit2), str(amount_a) + '\n')
    print(f" The account balance of account{name2} is {amount_a:.2f} $")
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!