Question: Can someone help me with my python code? I want to make it so it automatically assigns a new account ID when the user adds
Can someone help me with my python code? I want to make it so it automatically assigns a new account ID when the user adds a new account. As you can see its not counting right and it is stuck at 1001. Thank you.\ import pickle import os import pathlib class Account: accNo = 0 name = "" deposit = 0 type = "" def createAccount(self): self.accNo = 1000 self.name = str(input("\tEnter the account holders name: ")) while self.name.isnumeric(): print("\tEnter characters only") self.name = str(input("\tEnter the account holders name: ")) self.type = str(input("\tEnter the type of account [C/S]: ")) while (self.type != 'C' and self.type != 'S'): print("\tInvalid input") self.type = str(input("\tEnter the type of account [C/S]: ")) while True: try: self.deposit = eval(input("\tEnter the initial deposit amount: ")) while self.deposit < 0: print("\tError! Deposit cannot be negative") self.deposit = eval(input("\tEnter your account number: ")) break except NameError: print("\tError! Account must be a number") print("\tAccount Created") self.accNo += 1 def showAccount(self): print("Account Number: ", self.accNo) print("Account Holder Name: ", self.name) print("Type of Account: ", self.type) print("Balance: ", self.deposit) def modifyAccount(self): print("Account Number: ", self.accNo) self.name = input("Modify Account Holder Name: ") self.type = input("Modify type of Account: ") self.deposit = eval(input("Modify Balance: ")) def report(self): print(self.accNo, " ", self.name, " ", self.type, " ", self.deposit) def getAccountNo(self): return self.accNo def getAccountHolderName(self): return self.name def getAccountType(self): return self.type def getDeposit(self): return self.deposit def intro(): print(" ************************") print(" BANK MANAGEMENT SYSTEM ") print("************************") print(" Brought To You By:") print("\tMJB Bank & Trust") def writeAccount(): account = Account() account.createAccount() writeAccountsFile(account) def displayAll(): file = pathlib.Path("accounts.data") if file.exists(): infile = open('accounts.data', 'rb') mylist = pickle.load(infile) print("\t|{0:>10}|".format("Acc. No."), "{0:>10}|".format("Name"), "{0:>6}|".format("Type"), "{0:>8}|".format("Balance")) print("\t------------------------------------------") for item in mylist: print("\t|{0:>10}|".format(item.accNo), "{0:>10}|".format(item.name), "{0:>6}|".format(item.type), "{0:>8}|".format(item.deposit)) infile.close() else: print("\tNo records to display") def displaySp(): file = pathlib.Path("accounts.data") if file.exists(): num = int(input("\tEnter the account number: ")) infile = open('accounts.data', 'rb') mylist = pickle.load(infile) found = False infile.close() for item in mylist: if item.accNo == num: print("\tYour account Balance is = ", item.deposit) found = True if not found: print("\tNo existing record with this number") else: print("\tNo records to search") def writeAccountsFile(account): file = pathlib.Path("accounts.data") if file.exists(): infile = open('accounts.data', 'rb') oldlist = pickle.load(infile) oldlist.append(account) infile.close() os.remove('accounts.data') else: oldlist = [account] outfile = open('newaccounts.data', 'wb') pickle.dump(oldlist, outfile) outfile.close() os.rename('newaccounts.data', 'accounts.data') # start of the program ch = "" intro() while ch != 8: # system(cls); print(" ***********************") print(" MAIN MENU ") print("***********************") print("1. NEW ACCOUNT") print("2. ALL ACCOUNT HOLDER LIST") ch = input("Select Your Option (1-2): ") # system("cls"); if ch == '1': writeAccount() elif ch == '2': displayAll() else: print("\tInvalid choice") Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
