A positive integer m is a sum of squares if it can be written as k + l where k > 0, l > 0 and both k and l are perfect squares. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

A positive integer m is a sum of squares if it can be written as k + l where k > 0, l > 0 and both k and l are perfect squares.

A positive integer m is a sum of squares if it can be written as k + l where k > 0, l > 0 and both k and l are perfect squares. Write a Python function sumofsquares(m) that takes an integer m returns True if m is a sum of squares and False otherwise. (If m is not positive, your function should return False.) Here are some examples to show how your function should work. >>> sumofsquares(41) True >>> sumofsquares(30) False >>> sumofsquares(17) True https://www.sololearn.com/discuss/1089286/?ref=app

23rd Feb 2018, 4:25 PM
SUNIL PATIL
SUNIL PATIL - avatar
5 Answers
+ 1
def sumofsquares(n): if n<0: return False for i in range(1, int(n**0.5) + 1 ): for j in range(1, int(n**0.5) + 1 ): m = i**2 + j**2 if m == n: return True elif m > n: break return False def wellbracketed(ss): depth=0 for i in range(len(ss)): char = ss[i] if char=="(": depth+=1 elif char==")": if depth>0: depth-=1 else: return False return depth==0 def rotatelist(ll, shft): l = len(ll) shft = shft % l ans = ll[l-shft:] + ll[:l-shft] return ans Is this answer correct ? Plzz verify it and suggest me the changes
24th Feb 2018, 4:00 PM
Akanksha Vishwakarma
Akanksha Vishwakarma - avatar
23rd Feb 2018, 5:06 PM
sayan chandra
sayan chandra - avatar
+ 1
Define a Python function ascending(l) that returns True if each element in its input list is at least as big as the one before it. Define a Python function alternating(l) that returns True if the values in the input list alternately go up and down (in a strict manner). A two dimensional matrix can be represented in Python row-wise, as a list of lists: each inner list represents one row of the matrix. For instance, the matrix1 2 3 4 5 6 would be represented as [[1,2,3],[4,5,6]]. Write a Python function matmult(m1,m2) that takes as input two matrices using this row-wise representation and returns the matrix product m1*m2 using the same representation. You may assume that the input matrices are well-formed and have compatible dimensions. For instance: >>> matmult([[1,2],[3,4]],[[1,0],[0,1]]) [[1,2],[3,4]] >>> matmult([[1,2,3],[4,5,6]],[[1,4],[2,5],[3,6]]) [[14, 32], [32, 77]]
27th Feb 2018, 4:58 PM
SUNIL PATIL
SUNIL PATIL - avatar
0
it works.... nice job... no changes everything is fine..
24th Feb 2018, 4:24 PM
SUNIL PATIL
SUNIL PATIL - avatar
0
Histogram Write a Python function histogram(l) that takes as input a list of integers with repetitions and returns a list of pairs as follows: for each number n that appears in l, there should be exactly one pair (n,r) in the list returned by the function, where r is is the number of repetitions of n in l. the final list should be sorted in ascending order by r, the number of repetitions. For numbers that occur with the same number of repetitions, arrange the pairs in ascending order of the value of the number.
10th Mar 2018, 3:08 PM
SUNIL PATIL
SUNIL PATIL - avatar