def generateMenu(c): former = c.lst().copy() if c.strategy() == 'readfile': pos = input('Enter the start position (0 required for the 1st time): ') if len(c.lst()) == 0: pos = 0 print('Set to 0') else: pos = v.validatePositiveInt(pos, 'Start position') fn = input('Enter filename (.txt): ') fn = v.validateFileName(fn) c.executeStrategy(pos, fn) elif c.strategy() == 'iterator': pos = input('Enter the start position (0 required for the 1st time): ') if len(c.lst()) == 0: pos = 0 print('Set to 0') else: pos = v.validatePositiveInt(pos, 'Start position') n = input('Enter quantity of numbers you want to add: ') n = v.validatePositiveInt(n, 'Quantity') c.executeStrategy(pos, n) Event.update('add', former, pos, c.lst()) print('Collection succesfully generated!')
def sliceMenu(c): start = input('Enter start position of deletion: ') end = input('Enter end position of deletion: ') start = v.validatePositiveInt(start, 'Start') end = v.validatePositiveInt(end, 'End') if start > end or end >= len(c.lst()): raise ValueError('Bad index value') for i in range(end - start + 1): c.lst().pop(start) print('Items succesfully deleted!')
def sliceMenu(c): start = input('Enter start position of deletion: ') end = input('Enter end position of deletion: ') start = v.validatePositiveInt(start, 'Start') end = v.validatePositiveInt(end, 'End') if start > end or end >= len(c.lst()): raise ValueError('Bad index value') former = c.lst().copy() for _ in range(end - start + 1): c.lst().pop(start) Event.update('remove', former, [start, end], c.lst()) print('Items succesfully deleted!')
def generateWithIterator(c): print('Please fill the list using \'iterator\' strategy:') c.setStrategy(IteratorStrategy()) former = c.lst().copy() pos = 0 n = input('Enter quantity of numbers you want to add: ') n = v.validatePositiveInt(n, 'Quantity') c.executeStrategy(pos, n) Event.update('add', former, pos, c.lst()) print('Collection succesfully generated!')