-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmspect.py
More file actions
54 lines (41 loc) · 1.02 KB
/
mspect.py
File metadata and controls
54 lines (41 loc) · 1.02 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
k = [15,28,16,14,14,13,15,15]
def massspect(n,fragment):
n,m = mspect1(n,fragment),mspect2(n,fragment)
print "Front="+str(n)
print "Back="+str(m)
def mspect1(n,fragment):
working = 0
index = 0
while working != fragment:
working += n[index]
index += 1
if index == len(n):
return "Error"
return n[0:index]
def mspect2(n,fragment):
working = 0
index = len(n) - 1
while working != fragment:
working += n[index]
index -= 1
if index == -1:
return "Error"
return n[index+1:]
def arraysum(lst):
if lst == []:
return 0
summ = 0
for i in range(0,len(lst)):
summ += lst[i]
return summ
def emassspect(n,fragment):
index = 0
lst = []
for i in range(0,len(n)):
lst.append(n[i])
if arraysum(lst) > fragment:
lst = lst[1:]
if arraysum(lst) == fragment:
return lst
print lst
return "Error"