Sum of Squares List
Python
Medium
2 views
Problem Description
Read n and n integers. Write function sum_sq(arr) to return sum of squares and output it.
Input Format
First line n. Second line n integers.
Output Format
One integer sum.
Official Solution
import sys
p=sys.stdin.read().strip().split()
if not p: sys.exit(0)
n=int(p[0])
a=list(map(int,p[1:1+n]))
def sum_sq(arr):
s=0
for x in arr:
s+=x*x
return s
sys.stdout.write(str(sum_sq(a)))
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!