-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvectors_initialize.py
More file actions
149 lines (132 loc) · 4.96 KB
/
vectors_initialize.py
File metadata and controls
149 lines (132 loc) · 4.96 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
print(
'-----------------------------------------\n'\
'Python Library for Linear Algebra Operations | Vectors Initialization:\n'\
'-----------------------------------------\n'
)
print(
'Task:\n'\
'-----------------------------------------\n'\
'Write a simple Python module for creating different vectors on the different dimensions.\n'
)
print(
'Solution:\n'\
'-----------------------------------------'\
)
#Default function for handling execution loop:
def execution_loop():
data = int(input("Do you want to try again ? Enter [1] - for continue / [0] - for quit :\n>>>"))
if data == 1:
return True
elif data == 0:
return False
else:
print("Error: you entered incorrect command. Please, try again...")
execution_loop()
def vector_loop():
data = int(input("Do you want to add a new coordinate ? Enter:\n[2] - for adding a new coordinate;\n[1] - for adding a new vector;\n[0] - for open operations panel\n>>>"))
if data == 2:
return 2
elif data == 1:
return 1
elif data == 0:
return 0
else:
print("Error: you entered incorrect command. Please, try again...")
vector_loop()
def vector_loop_max():
data = int(input("Do you want to add a new vector ? Enter:\n[1] - for adding a new vector;\n[0] - for open operations panel\n>>>"))
if data == 1:
return 1
elif data == 0:
return 0
else:
print("Error: you entered incorrect command. Please, try again...")
vector_loop_max()
#Module for creating a simple mathematical vectors on the dimension:
class Vector(object):
def __init__(self, coordinates):
try:
if not coordinates:
raise ValueError
self.coordinates = tuple(coordinates)
self.dimension = len(coordinates)
except ValueError:
raise ValueError('The coordinates must be nonempty')
except TypeError:
raise TypeError('The coordinates must be an iterable')
def __str__(self):
return 'Vector {}'.format(self.coordinates)
def __eq__(self, v):
return self.coordinates == v.coordinates
#Function for loop-creating new vectors using user's data:
def vectors_loop_creating():
vectors = []
vector_counter = 1
coordinate_counter = 1
vector_input_control = True
while vector_input_control:
#print("Please, enter all coordinates of the %d vector:" % vector_counter)
#print(f'Please, enter all coordinates of the {vector_counter}-vector:')
#print(f"Please, enter all coordinates of the {vector_counter}-vector:")
print("Please, enter all coordinates of the %d-vector" % vector_counter)
vector = []
coordinate_counter = 1
coordinate_input_control = True
while coordinate_input_control:
#print("Please, enter %d-st coordinate:" % coordinate_counter)
#print(f'Please, enter {coordinate_counter}-st coordinate:')
print("Please, enter %d-st coordinate:" % coordinate_counter)
vector.append(int(input(">>>")))
if len(vector) == 3:
#print("You almost entered the maximum number of coordinates on the %d-vector." % vector_counter)
#print(f'You almost entered the maximum number of coordinates on the {vector_counter}-vector. The maximum number of coordinates should be less of equal to 3.')
print("You almost entered the maximum number of coordinates on the %d-vector. The maximum number of coordinates should be less of equal to 3." % vector_counter)
coordinate_input_control = False
data = vector_loop_max()
if data == 1:
vector_input_control = True
else:
vector_input_control = False
break
data = vector_loop()
if data == 2:
coordinate_input_control = True
elif data == 1:
coordinate_input_control = False
break
else:
coordinate_input_control = False
vector_input_control = False
break
coordinate_counter = coordinate_counter + 1
vector_counter = vector_counter + 1
print("You entered vector with coordinates: ", vector)
vectors.append(Vector(vector))
return vectors
#Function for handling all operations on the vectors:
def vectors_operations_handling(vectors):
print("You entered vectors with coordinates:")
v_counter = 0
for vector in vectors:
print('{0}: '.format(v_counter + 1))
print(vector)
v_counter = v_counter + 1
#Default parameters for handling execution loop:
again_exec = True
counter_exec = 0
#Default loop for handling execution:
while again_exec:
vectors = []
vectors = vectors_loop_creating()
vectors_operations_handling(vectors)
again_exec = execution_loop()
counter_exec = counter_exec + 1
#The end of execution:
if again_exec == False:
print("Program was executed: ",counter_exec, ' times.')
break
print(
'\n-----------------------------------------\n'\
'Copyright 2019 Vladimir Pavlov. All Rights Reserved.\n'\
'-----------------------------------------'
)