patternpythonMinor
Banking system program
Viewed 0 times
systembankingprogram
Problem
I'm creating a Banking system program using Python, and the requirements of this program are very basic:
I've managed to program the basic functionality, and now I'm in need of any feedback on how to improve my code, in order to create a program with CLEAR, CONCISE AND STRUCTURED CODE. I'd very much appreciate any kind of feedback, be it code specific feedback or feedback on my general coding, as I'm a beginner to programming in general.
PS: Im aware that the program needs error handling, and Im already working on it.
```
import pyodbc
cnxn = pyodbc.connect('Driver={ODBC Driver 13 for SQL Server};Server=GLOBALGROWTH\SQLEXPRESS;Database=IDLBANKSYS;Trusted_Connection=yes;')
cursor = cnxn.cursor()
class CLIMenu(object):
def __init__(self, options: list):
self.options=options
def PrintCLIMenu(self):
print('=' 30, '\tIDL BANKING SYSTEM', '=' 30, sep='\n')
print()
print("PLEASE ENTER THE NUMBER CORRESPONDING TO YOUR DESIRED COMMAND IN THE PROMPT BELOW :\n ", *self.options,
sep='\n')
print()
def GetUserInput(self):
return input(">>>: ")
def RegisterCustomer():
RegisterCustomerForm = [input("NATIONAL IDENTITY CARD NUMBER : "), input("FULL NAME IN CAPITALS : "),
input("DATE OF BIRTH AS DD/MM/YYYY : "),
input("ADDRESS : "), input("CONTACT NUMBER : "), input("EMAIL ADDRESS : ")]
cursor.execute("INSERT into customer VALUES(?,?,?,?,?,?)", *RegisterCustomerForm)
cnxn.commit()
print("REGISTRATION SUCCESSFUL")
cursor.execute("INSERT into account VALUES(?,?,0)", RegisterCustomerForm[0], RegisterCustomerForm[1])
cnxn.commit()
def ViewCustomer():
CustToView=input("PLEASE ENTER THE NATIONAL IDENTITY CARD NUMBER OF THE CUSTOMER YOU WISH TO VIEW : ")
cursor.execute("SELECT * FROM customer WHERE Cust_
- Register and maintain Customer Details
- Update Account balance through Deposits and Withdrawals
I've managed to program the basic functionality, and now I'm in need of any feedback on how to improve my code, in order to create a program with CLEAR, CONCISE AND STRUCTURED CODE. I'd very much appreciate any kind of feedback, be it code specific feedback or feedback on my general coding, as I'm a beginner to programming in general.
PS: Im aware that the program needs error handling, and Im already working on it.
```
import pyodbc
cnxn = pyodbc.connect('Driver={ODBC Driver 13 for SQL Server};Server=GLOBALGROWTH\SQLEXPRESS;Database=IDLBANKSYS;Trusted_Connection=yes;')
cursor = cnxn.cursor()
class CLIMenu(object):
def __init__(self, options: list):
self.options=options
def PrintCLIMenu(self):
print('=' 30, '\tIDL BANKING SYSTEM', '=' 30, sep='\n')
print()
print("PLEASE ENTER THE NUMBER CORRESPONDING TO YOUR DESIRED COMMAND IN THE PROMPT BELOW :\n ", *self.options,
sep='\n')
print()
def GetUserInput(self):
return input(">>>: ")
def RegisterCustomer():
RegisterCustomerForm = [input("NATIONAL IDENTITY CARD NUMBER : "), input("FULL NAME IN CAPITALS : "),
input("DATE OF BIRTH AS DD/MM/YYYY : "),
input("ADDRESS : "), input("CONTACT NUMBER : "), input("EMAIL ADDRESS : ")]
cursor.execute("INSERT into customer VALUES(?,?,?,?,?,?)", *RegisterCustomerForm)
cnxn.commit()
print("REGISTRATION SUCCESSFUL")
cursor.execute("INSERT into account VALUES(?,?,0)", RegisterCustomerForm[0], RegisterCustomerForm[1])
cnxn.commit()
def ViewCustomer():
CustToView=input("PLEASE ENTER THE NATIONAL IDENTITY CARD NUMBER OF THE CUSTOMER YOU WISH TO VIEW : ")
cursor.execute("SELECT * FROM customer WHERE Cust_
Solution
-
You are using the same
You should extract it to a new function and call it twice.
-
In the main function you should extract the code that's under the
-
The
See an example here.
You are using the same
For loop twice (and the print that follows it).You should extract it to a new function and call it twice.
-
In the main function you should extract the code that's under the
if condition, and the code that's under elif to new functions.-
The
if statements for UserInput should be replaced with a dictionary. See an example here.
Context
StackExchange Code Review Q#160668, answer score: 3
Revisions (0)
No revisions yet.