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

203
Views
¿Cómo crear una administración de cuenta simple usando python?

Me gustaría ampliar la administración de mi cuenta al permitir que los clientes abran una nueva cuenta con su nombre y saldo. El número de cuenta debe generarse automáticamente (consecutivo).

También me gustaría agregar lo siguiente:

  • No debería ser posible sobregirar la cuenta.
  • Ya no debería ser posible depositar o retirar una cantidad negativa.

Desafortunadamente no puedo llegar más lejos aquí.

Así es como se ve mi archivo account.txt:

 1, Max Mustermann, 1000.0 2, Nora Mustermann, 790.0 3, Tomas Mustermann, 400.0

Esta es mi codificación:

 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

En primer lugar, no debe almacenar datos de usuario en un archivo txt. No está encriptado y es prominente para el robo de datos. Es posible que desee buscar en una base de datos como sqlite en caso de que desee almacenarla localmente o MySQL en caso de que desee almacenarla en un servidor (recomiendo SQlite para comenzar). También es mucho más intuitivo agregar, editar y eliminar elementos de esta manera que editar un archivo txt sin formato.

Con respecto a los valores negativos es bastante fácil. Solo verifica si el valor no es negativo como este:

 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')

Para evitar que un usuario retire un valor superior al que tiene actualmente en su cuenta, simplemente compruebe si el valor retirado es superior al de la cuenta.

 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!