Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def checkTransaction(day, value, t_type, dscr):
- '''
- The function checks if the parameters match the description
- :param day:
- :param value:
- :param t_type:
- :param dscr:
- :return: True - parameters are ok
- False - if they don't
- '''
- if(day < 1 or day > 30):
- return False
- if(value < 1):
- return False
- if(t_type != 'in' and t_type != 'out'):
- return False
- return True
- def constructTransaction(transactions, day, value, t_type, dscr):
- '''
- The function takes list and gives it the parameters of the transaction
- :param day: int
- :param value: int
- :param t_type: str
- :param dscr: str
- :return: list of 4 elements if the parameters are valid
- empty list if they are not
- '''
- if( checkTransaction(day, value, t_type, dscr) == False):
- print('The parameters are invalid')
- transactions.append( day )
- transactions.append( value )
- transactions.append( t_type )
- transactions.append( dscr )
- def addTransaction(tees, transaction ):
- '''
- The function adds a transaction to the history
- :param tees: history of saves
- :param transaction: list of 4 parameters
- :return:
- '''
- last_save = []
- last_save += getTransactions( tees )
- last_save.append( transaction )
- tees.append( last_save )
- def getTransactions( tees ):
- '''
- The function returns the current list of transactions
- :param tees: history of saves
- :return:
- '''
- return tees[ len( tees ) - 1 ]
- def checkPosition(transactions, pos):
- ''''''
- if(pos < len(transactions)):
- return True
- return False
- def getPosition( transactions, pos ):
- if(checkPosition( transactions, pos ) == False):
- print('Out of range')
- return []
- return transactions[ pos ]
- def printTransactions(tees):
- '''
- The function prints all the currnet transactions
- :param tees: history of saves
- :return:
- '''
- aux = getTransactions( tees )
- for i in aux:
- print( i )
- def createTransaction(tees, day, value, t_type, dscr):
- '''
- The function creates a new transaction and adds it to the history
- :param tees: history of saves
- :param day:
- :param value:
- :param t_type:
- :param dscr:
- :return:
- '''
- aux = []
- constructTransaction(aux, day, value, t_type, dscr)
- addTransaction(tees, aux)
- def loadTransactions( tees ):
- '''
- The function adds 10 transactions to the history
- :param tees: history of saves
- :return:
- '''
- createTransaction(tees, 1, 1000, 'in', 'verify')
- createTransaction(tees, 2, 20, 'out', 'verify')
- createTransaction(tees, 2, 489, 'out', 'verify')
- createTransaction(tees, 3, 200, 'in', 'verify')
- createTransaction(tees, 4, 300, 'out', 'verify')
- createTransaction(tees, 5, 29, 'out', 'verify')
- createTransaction(tees, 5, 2000, 'in', 'verify')
- createTransaction(tees, 5, 500, 'out', 'verify')
- createTransaction(tees, 6, 50, 'out', 'verify')
- createTransaction(tees, 7, 100, 'out', 'verify')
- def readCommand():
- comm = input('command > ')
- pos = comm.find(' ')
- if pos == -1:
- return (comm, [])
- command = comm[:pos]
- parameters = comm[pos + 1:]
- parameters = parameters.split(" ")
- for i in range(len(parameters)):
- parameters[i] = parameters[i].strip()
- return (command, parameters)
- def print_commands():
- print('The possible commands are: ')
- print('-> add')
- print('-> insert')
- print('-> remove')
- print('-> list')
- def start( tees = []):
- pair = readCommand()
- cmd = pair[ 0 ]
- parameters = pair[ 1 ]
- if(cmd == 'list' and parameters == []):
- printTransactions( tees )
- start( tees )
- def initialize():
- tees = [ [] ]
- print_commands()
- loadTransactions( tees )
- start( tees )
- initialize()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement