Squares From 1 to N
Python
Easy
4 views
Problem Description
Read n, output square of every number from 1 to n, one per line.
Input Format
One integer n.
Output Format
n lines squares.
Official Solution
import sys
s=sys.stdin.read().strip()
try:
n=int(s)
except Exception:
n=0
out=[]
for i in range(1,n+1):
out.append(str(i*i))
sys.stdout.write('\
'.join(out))
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!