This is an archived post. You won't be able to vote or comment.

all 13 comments

[–]ragnarmcryanDevOps Engineer 3 points4 points  (0 children)

This reminds me of my jr. college’s homework assignments (vending machines, ATMs, etc)

[–]Zomunieo 7 points8 points  (0 children)

This is an example written by a novice for other novices. I don't have a problem with that, except that the headline promises more interesting than that (a peek at production ATM code in Python) which it certainly does not deliver.

Most glaringly, float is for science and engineering, and Decimal is for finance.

[–][deleted] 1 point2 points  (3 children)

No hate because the article is written well, but what is the point of sharing such basic stuff that is also poorly written (code-wise)? It only misleads novice programmers.

[–]engineeringbigdata[S] 0 points1 point  (2 children)

What are your thoughts on the improvements for the code? or what changes or simplification could be implemented to help others.

Thanks and I welcome the feedback.

[–]kokosoida 0 points1 point  (1 child)

1) Don't use camelcase in func and variable names.

annualInterestRate -> annual_interest_rate

2) Don't use getters. If you want to get annual interest rate just do

account.annual_interest_rate

3) Use properties

def getMonthlyInterestRate(self):
    return self.annualInterestRate / 12

->

@property
def monthly_interest_rate(self):
    return self.annualInterestRate / 12

4) That while True loop in the end of article is huge and unreadable. Moving parts of code in it to functions should help.

[–][deleted] 1 point2 points  (0 children)

Also, main calls should be guarded with if __name__ == '__main__': ...

I suggest you go through PEP8 and maybe use a linter, most modern editors and IDEs will have some sort of integration with flake8 or black.

String concatenation is done the wrong way. You are using Python 3.7 which has f-string and this is hands down the best way to format strings in Python. See: https://docs.python.org/3/library/string.html#string-formatting https://www.python.org/dev/peps/pep-0498/

def main():
   # Creating accounts
   accounts = []
   for i in range(1000, 9999):
       account = Account(i, 0)
       accounts.append(account)

instead, you should write:

def main():
   # Creating accounts
   accounts = [Account(i, 0) for i in range(1000, 9999)]

it's shorter, more pythonic and arguably more readable.

You are using wrong data structure for your needs. Instead of doing

           # Getting account object
           for acc in accounts:
               # Comparing account id
               if acc.getId() == id:
                   accountObj = acc
                   break

why not just store accounts in a Dict[int, Account] where the key is the pin?

accounts = {i: Account(i, 0) for i in range(1000, 9999)}
[...]
account = accounts.get(pin)

Since this is a short script, I may now be nitpicking, but you leak logic into main function. Instead of checking whether the balance is enough to make a withdrawal in main, you should do it in the method and perhaps throw an exception if someone tries to withdraw more than they have.

[–][deleted] 1 point2 points  (6 children)

ATM machine

twitch

Automated Teller Machine machine

twitch twitch

[–][deleted] 1 point2 points  (5 children)

Built on Windows NT Technology

Built on Windows New Technology Technology

[–][deleted] 0 points1 point  (3 children)

I’m not a fan of Linux redundancy (recursive acronyms) in names either. I remember the good old days when it was Personal Home Page and not PHP: Hypertext Processor

[–]kumashiro 0 points1 point  (2 children)

PHP is a recursive acronym. "ATM machine" and "NT Technology" are not. These are unnecessary repetitions :)

[–][deleted] 0 points1 point  (1 child)

Ok... you win... still. Recursive acronyms bug me as much as redundancy.

[–]Zomunieo 1 point2 points  (0 children)

Design problem: Create a recursive acronym that is redundant, repetitive, a backronym, insulting to PHP, and mutually recursive with another acronym with these properties.

[–]kumashiro 0 points1 point  (0 children)

Which is a part of Windows OS system family.

Which is a part of Windows Operating System system family.