Last active
December 1, 2016 06:18
-
-
Save mhsharifi96/671bd1c616bc2a94e21e6b04f30cbd21 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3.5 | |
class tape: | |
def __init__(self,Sum,p): | |
self.sum_a=Sum | |
self.p=p | |
def SUM(self): | |
Min=Sum | |
for i in range(p): | |
sum_left=sum(a[:i]) | |
sum_right=Sum-sum_left | |
if (abs(sum_right-sum_left)<Min): | |
Min=abs(sum_right-sum_left) | |
return Min | |
def unlimited(): | |
a=[] | |
Sum=0 | |
while True: | |
i=input("a:") | |
if i =='q'or i=='': | |
return (a,Sum ) | |
else: | |
j=int(i) | |
a.append(j) | |
Sum=Sum+j | |
a,Sum=unlimited() | |
print("sum_a: ",Sum) | |
p=int(input("p : ")) | |
t=tape(Sum,p) | |
MIN=t.SUM() | |
print("MIN : ",MIN) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
getting input from user is not expected.
you should consider a pointer to array and pass this array with its length to the function.