Write a Python program to accept a positive integer n from the user and then print the following pattern using nested loops. For example, if n = 5, the output should be:

*

* *

* * *

* * * *

* * * * *

Answer:

Answer by student

n = int(input( "Enter a positive integer: " ))

for i in range( 1 , n+ 1 ):

  for j in range(i):

    print( "*" , end= " " )

  print()

Detailed answer by teachoo

The rest of the post is locked. Join Teachoo Black to see the full post.

Go Ad-free
Davneet Singh's photo - Co-founder, Teachoo

Made by

Davneet Singh

Davneet Singh has done his B.Tech from Indian Institute of Technology, Kanpur. He has been teaching from the past 14 years. He provides courses for Maths, Science, Social Science, Physics, Chemistry, Computer Science at Teachoo.