Skip to content

Instantly share code, notes, and snippets.

@mhsharifi96
Last active December 1, 2016 06:18
Show Gist options
  • Select an option

  • Save mhsharifi96/671bd1c616bc2a94e21e6b04f30cbd21 to your computer and use it in GitHub Desktop.

Select an option

Save mhsharifi96/671bd1c616bc2a94e21e6b04f30cbd21 to your computer and use it in GitHub Desktop.
#!/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)
@VahidSaadat

Copy link
Copy Markdown

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment