def create_matrix_init(): """ Collects needed data. """ matrix_types = { 'Null': 'null', 'Identity': 'identity', 'Known': 'known', 'Random': 'random', } type_ = matrix_types[tools.get_option(matrix_types)] rows = tools.get_integer('Number of rows: ') columns = rows if type_ != 'identity' else tools.get_integer('Number of columns: ') return create_matrix(rows, columns, type_)
def create_matrix(rows: int, columns: int, type_: str): """ Type can be: null / identity / known Null - full of 0. Identity - full of 0 except for the diagonal. Known - with given numbers. Random - random integers from 0 to 9 """ matrix = [] for r in range(rows): row = [] for c in range(columns): if type_ == 'null': row.append(0) elif type_ == 'identity': row.append(1) if r == c else row.append(0) elif type_ == 'known': row.append(tools.get_integer(f'Element in row {r + 1} column {c + 1}: ')) elif type_ == 'random': row.append(random.randint(0, 9)) matrix.append(row) prompt = f'{type_} matrix of {rows} rows and {columns} columns: ' return matrix, prompt
def check_attributes_init(): """Collects needed data.""" return check_attributes(tools.get_integer('Number to be assessed: '))
def series_constructor_init(): """Collects needed data.""" return series_constructor( tools.get_option(attributes_available), tools.get_integer('Number of elements: '), )
def fibonacci_series(elements=0) -> list: """ n = n-1 + n-2""" seq = [0, 1] for i in range(elements - len(seq)): seq.append(seq[i] + seq[i + 1]) return seq def padovan_series(elements=0) -> list: """ n = n-2 + n-3 """ seq = [0, 1, 1] for i in range(elements - len(seq)): seq.append(seq[i] + seq[i + 1]) return seq series_available = { 'Fibonacci': fibonacci_series, 'Padovan': padovan_series, } if __name__ == '__main__': series = tools.get_option(series_available) elements = tools.get_integer('Number of elements: ') result = series_available[series](elements) prompt = '{} sequence with the {} first elements: '.format( series, elements) tools.display(result, prompt)