Week-2 Assignment Solution (Last Date : 15/02/2020)
def threesquares(N) :
i = 0
while (i * i<= N) :
j= i
while (j * j <= N) :
k = j
while (k * k <= N) :
if (i * i + j * j + k * k == N) :
return True
k = k + 1
j = j + 1
i = i + 1
return False
def repfree(s):
a = set(s)
return len(a) == len(s)
def hillvalley(l):
if l == []:
return False
stop = -1
i = 1
flag = True
if l[0] > l[1]:
i = 1
for i in range(i, len(l)):
if l[i-1] < l[i]:
stop = i
break
if stop == -1:
return False
i = stop
for i in range(i, len(l)):
if l[i-1] > l[i]:
flag = False
break
return flag
elif l[0] < l[1]:
for i in range(1, len(l)):
if l[i-1] > l[i]:
stop = i
break
if stop == -1:
return False
for i in range(i, len(l)):
if l[i-1] < l[i]:
flag = False
break
return flag
else:
return False
Note: Copy the Code and Paste as it is without making any changes into it. If you have any queries Please do comment Below and Share among your friends.
No comments:
Post a Comment