Programming, Data Structures And Algorithms Using Python
Week 2 Programming Assignments
----------------------------------------------------------------------------------------
~~~THERE IS SOME INVISIBLE CODE HERE~~~
def threesquares(m):
if(m<0):
return(False)
l=[]
for i in range(0, int(m**0.5)+1):
l+=[i*i]
for i in l:
for j in l:
for k in l:
if(i+j+k==m):
return (True)
return(False)
def repfree(s):
for c in s:
count=0
for j in s:
if(j==c):
count=count+1
if (count >= 2):
return (False)
return(True)
def hillvalley(l):
dec = False
inc = False
c = 0
for i in range(len(l)-1):
if c > 1:
return False
right = l[i+1]
middle = l[i]
diff = right - middle
if diff > 0:
if dec:
c += 1
inc = True
dec = False
elif diff < 0:
if inc:
c += 1
dec = True
inc = False
if c == 1:
return True
return False
---------------------------------------------------------------------------------------
Don't forget to indent the code properly.
No comments:
Post a Comment
Keep your comments reader friendly. Be civil and respectful. No self-promotion or spam. Stick to the topic. Questions welcome.