Skip to main content
26 votes
Accepted

Validating Credit Card Numbers

First of all, you should encapsulate your functionality in a function, unless you really want to use your code only once. At the moment you would have to duplicate your code somewhat just to check a ...
Zeta's user avatar
  • 19.3k
20 votes
Accepted

Financial website scraper

Here a few suggestions (in no particular order) for improvements on your code: Make variables have locality The line: items = 1 is at the top of the method, ...
Stephen Rauch's user avatar
16 votes
Accepted

Basic Python OO bank account

Python doesn't have private anything but we still have a need to separate inners of a class from the public interface. By convention, attributes or methods whose name starts with a single underscore ...
301_Moved_Permanently's user avatar
16 votes

Financial website scraper

In addition to what @StephenRauch wrote in his excellent answer, let me add one more comment: Your class is completely useless. Not its functionality, which is fine, but it being a ...
Graipher's user avatar
  • 41k
14 votes

Basic Python OO bank account

In this answer I'm not going to review your code, but instead discuss the design of a book-keeping system. (I know that you're just using a bank account as an exercise, but an important part of ...
Gareth Rees's user avatar
  • 49.6k
12 votes

Validating Credit Card Numbers

You can do most of this with regex. Going through your requirements: It must only consist of digits (0-9). And so we can use [0-9] for each digit. It must ...
Peilonrayz's user avatar
  • 43.4k
11 votes
Accepted

Simple budget program

Here are the few things I've noticed after a first glance on the program: import os is not used, you can remove it () after the ...
alecxe's user avatar
  • 17.3k
10 votes

A simple Python class designed to facilitate investment portfolio analysis

time representation class Portfolio: ... start_date: str end_date: str I'm sad those aren't datetimes, or at least dates. Then we get validation (no ...
J_H's user avatar
  • 29.3k
9 votes
Accepted

How to use PHP Visibility method?

Yes, the original code is awful. It is 200 lines of spaghetti code; I have no idea what it does, it is impossible to reuse and extremely difficult to test, debug, or change. That doesn't necessarily ...
tim's user avatar
  • 25.1k
9 votes

Basic Python OO bank account

In Python you can have multiple functions and classes in a single file (module) but is it considered bad practice to do so? You can write as many functions and classes within a Python module as ...
Billal Begueradj's user avatar
8 votes
Accepted

Convert an amount to Indian Notation

1. Style guides leave two empty lines before each function (when you're not inside of a class) Python is not C; don't use ; put a space before and after operands. <...
Grajdeanu Alex's user avatar
8 votes

Financial website scraper

You should also split the code in functional parts, and not mix the IO (print(...)) with generating the result base_url First you generate the base_url ...
Maarten Fabré's user avatar
8 votes

Bank Management System

I see a number of things that may help you improve your program. Use the required #includes The code uses std::find which ...
Edward's user avatar
  • 66.5k
7 votes

Bitcoin trading system

In these screening situations, you only get a few seconds to make a good first impression. Unfortunately, this line already makes a bad impression: ...
200_success's user avatar
7 votes

For a given balance and an annual interest rate, calculate the minimum fixed monthly payment to pay off debt in a year

This is a problem that can be solved exactly with a little math, so there should be no need to program a search. Suppose that we borrow initial capital \$c\$ at a monthly interest rate \$r\$, paying ...
Gareth Rees's user avatar
  • 49.6k
7 votes

Validating Credit Card Numbers

Your val_rep function can also be simplified with regular expressions by using backreferences (see the \number syntax). Here <...
User789's user avatar
  • 71
6 votes
Accepted

For a given balance and an annual interest rate, calculate the minimum fixed monthly payment to pay off debt in a year

General comments use a consistent style: space after a comma, or not; spaces around operators, or not; even two spaces sometimes. Python has an official style guide called PEP 8 which is worth a read,...
301_Moved_Permanently's user avatar
6 votes

Banking application for practice

It's not clear what TransactionReport is, but your class creates one and then doesn't do anything to or with it. If the report is modified through public ...
Scott Hannen's user avatar
6 votes

Banking application for practice

You already have a good answer from Scott (I'll add that I've never mocked anything in my life, but DependancyInversion and Injection are valuable design tools even when you ignore testing (which I am ...
VisualMelon's user avatar
  • 7,431
6 votes

A simple Python class designed to facilitate investment portfolio analysis

You've mixed degrees of freedom by computing some of the stats with Pandas (\$N-1\$) and others with NumPy (\$N\$): pandas.Series.std (default ...
tdy's user avatar
  • 1,589
5 votes

Calculating the interest on a series of loans

Do not represent monetary amounts as a decimal type; use an integer type instead. Try to avoid the use of using namespace std. You could still allow the user to ...
Jamal's user avatar
  • 34.9k
5 votes
Accepted

IRS Tax Calculator in Java

You are right, you over-complicated the code. My comments on it: Avoid using static state (here's a good explanation on why). Reuse code. If you start seeing that ...
MiguelAraCo's user avatar
5 votes
Accepted

App that calculates interest into a monthly payment

My honest opinion would be to make an interest calculator class, but we can work on a single function. If you do not already have some input validation elsewhere, I would consider the use of Double....
Chandler Turner's user avatar
5 votes

Validating Credit Card Numbers

You can massively simplify this by using regular expressions. Python includes an efficient module for that, named re (short for regular expressions). In this case, ...
Daniel's user avatar
  • 4,490
5 votes

Simple budget program

The while not x: loop can be replaced with a while True loop and you can break out of it using ...
Ashwini Chaudhary's user avatar
5 votes

Simple budget program

DRY and Data Structures Income and expenses are the same thing, just with different signs. You can cut about half your code by more fully leveraging this. Currently, each of the two have a list of ...
BenC's user avatar
  • 2,738
5 votes
Accepted

Bank ATM machine in Ruby

This is my first review, so please bear with me. I'll start with atm.rb: ...
thesecretmaster's user avatar
5 votes

Reversible tax calculator class

In my opinion, you should go for number 1 (with one small change). Reasons for choosing this one: Easy to modify - you can add new FromX method Clear - it ...
MaLiN2223's user avatar
  • 1,044
5 votes
Accepted

Calculate quote volumes (for a financial instrument) within numeric constraints

Bug adjust_volume(0) presently results in: UnboundLocalError: local variable 'bid_volume' referenced before assignment since ...
AJNeufeld's user avatar
  • 33.7k
5 votes
Accepted

Simple credit card validation with Luhn's Algorithm

Getting the First 2 Digits of a Number A solution for this in constant space and time is already documented in this answer: ...
C.Nivs's user avatar
  • 2,947

Only top scored, non community-wiki answers of a minimum length are eligible