Print 1 to N
Python
Easy
3 views
Problem Description
Read integer n, output numbers from 1 to n in one line separated by spaces. If n is 0, output nothing.
Input Format
One integer n.
Output Format
One line numbers.
Official Solution
import sys
s=sys.stdin.read().strip()
if not s: sys.exit(0)
n=int(s)
if n<=0:
sys.stdout.write('')
else:
out=[]
for i in range(1,n+1):
out.append(str(i))
sys.stdout.write(' '.join(out))
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!