jeudi 1 août 2019

How to generate pyramid of numbers (using only 1-3) using Python?

I'm wondering how to create a pyramid using only element (1,2,3) regardless of how many rows.

For eg. Rows = 7 ,

1
22
333
1111
22222
333333
1111111

I've have tried creating a normal pyramid with numbers according to rows.

eg.

1
22
333
4444
55555
666666

Code that I tried to make a Normal Pyramid

    n = int(input("Enter the number of rows:"))

    for rows in range (1, n+1):  
        for times in range (rows): 
            print(rows, end=" ")

        print("\n")

Aucun commentaire:

Enregistrer un commentaire