Thursday, November 5, 2020

The Joy of Computing Using Python Week-7 Programming Assignment 1: Printing Pattern

 



Programming Assignment 1: Printing Pattern

Due on 2020-11-05, 23:59 IST
In this assignment, you have to write a program to print a pattern of numbers.
The input should be the number of rows.
Your program should print this pattern where the first row contains only one element i.e 1.
The second row should contain two elements i.e. 1 and 2 separated by a space.
The third row should contain three elements i.e. 1, 2 and 3 separated by a space.

Input Format:
The first line of the input contains a number n which represents the number of rows.

Output Format:
There should be n rows with each row containing a list of numbers according to the pattern.

Example-1:

Input:
3

Output:
1
1 2
1 2 3

Example-2:

Input:
4

Output:
1
1 2
1 2 3
1 2 3 4

Explanation: In the first example the input was 3. Hence there are 3 rows. The first row has element 1. The second row contains two elements 1 and 2 and the third row contains 1, 2 and 3 separated by a space.

NOTE: There should not be any space after the each element of the last column and no new line after the last row.
Your last recorded submission was on 2020-11-03, 18:53 IST
Select the Language for this assignment. 
1
r=int(input())
2
l=[]
3
for i in range(1,r+1):
4
  if i==r:
5
    print(*l,i,end='')
6
  else:
7
    print(*l,i)
8
  l.append(i)

No comments:

Post a Comment