-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclean_code_result.py
57 lines (42 loc) · 1.59 KB
/
clean_code_result.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Feb 7 09:15:12 2025
@author: administrador
"""
# Definitions. -----------------------
statistics_padding = 27
def addition(number_a, number_b):
return number_a + number_b
def subtraction(number_a, number_b):
return number_a - number_b
operations = {
"add" : addition,
"subtract": subtraction
}
def vector_from_range(begin, end):
return [i for i in range(begin, end)]
def vector_operation(operation_name, vector_a, vector_b):
return [operations[operation_name](a, b) for a, b in zip(vector_a, vector_b)]
def vector_mean(vector):
return sum(vector) / len(vector)
def vector_print_statistics(vector_name, padding, vector):
minimum_tag = f"{vector_name} - Array minimum"
maximum_tag = f"{vector_name} - Array maximum"
mean_tag = f"{vector_name} - Array mean"
print(f"{minimum_tag: <{padding}}= {min(vector)}")
print(f"{maximum_tag: <{padding}}= {max(vector)}")
print(f"{mean_tag: <{padding}}= {vector_mean(vector)}")
# Main. ---------------------------------
vectors = {
"First": vector_from_range(0, 100),
"Second": vector_from_range(100, 200)
}
vectors["Sum"] = vector_operation("add", vectors["First"], vectors["Second"])
vectors["Difference"] = vector_operation("subtract", vectors["Second"], vectors["First"])
print(f'a1 = {vectors["First"]}\n')
print(f'a2 = {vectors["Second"]}\n')
print(f'a1 + a2 = {vectors["Sum"]}\n')
print(f'a2 - a1 = {vectors["Difference"]}\n')
for vector_name in vectors.keys():
vector_print_statistics(vector_name, statistics_padding, vectors[vector_name])