Print FLOYD'S Triangle

 

NOTE :  A Floyd's triangle is a right-angled triangle formed with natural numbers.

DIFFERENT TYPES OF PYTHON PROGRAMS TO PRINT FLOYD'S TRIANGLE :

  • FLOYD'S TRIANGL USING FOR LOOP
  • FLOYD'S TRIANGLE WITH N NUMBER OF ROWS
  • FLOYD'S TRIANGLE USING WHILE LOOP



1) PRINT FLOYD'S TRIANGLE USING FOR LOOP


Q  WRITE A PYTHON PROGRAM TO PRINT FLOYD'S TRIANGLE WITH 7 ROWS


CODE FOR THE ABOVE  PYTHON  PROGRAM :


num = 1
for i in range(7):
    for j in range(i+1):
        print(numend=" ")
        num = num+1
    print()


WRITTEN CODE FOR THE ABOVE PROGRAM :


num = 1

for i in range(7):

    for j in range(i+1):

        print(num, end=" ")

        num = num+1

    print()


OUTPUT :




2) PRINT A FLOYD'S TRIANGLE WITH N NO. OF ROWS


Q  WRITE A PYTHON PROGRAM TO PRINT FLOYD'S TRIANGLE WITH N NUMBER OF ROWS


CODE FOR THE ABOVE  PYTHON  PROGRAM :


print("Enter the length of the triangle : "end="")
len = int(input())

num = 1
for i in range(len):
    for j in range(i+1):
        print(numend=" ")
        num = num+1
    print()


WRITTEN CODE FOR THE ABOVE PROGRAM :


print("Enter the length of the triangle : ", end="")

len = int(input())


num = 1

for i in range(len):

    for j in range(i+1):

        print(num, end=" ")

        num = num+1

    print()


OUTPUT :



3) PRINT A FLOYD'S TRIANGLE USING WHILE LOOP


Q  WRITE A PYTHON PROGRAM TO PRINT FLOYD'S TRIANGLE USING WHILE LOOP


CODE FOR THE ABOVE  PYTHON  PROGRAM :


print("Enter the length of the triangle : "end="")
len = int(input())

num = 1
i = 0
while i < len:
    j = 0
    while j < i+1:
        print(numend=" ")
        num = num+1
        j = j+1
    print()
    i = i+1


WRITTEN CODE FOR THE ABOVE PROGRAM :


print("Enter the length of the triangle : ", end="")

len = int(input())


num = 1

i = 0

while i < len:

    j = 0

    while j < i+1:

        print(num, end=" ")

        num = num+1

        j = j+1

    print()

    i = i+1


OUTPUT :





Post a Comment

0Comments
Post a Comment (0)

Featured Highlighted Categories

You'll discover all of the most up-to-date bring innovative here.

Python List theory with List Programs
Get complete python lists theory and list basic and insane programs for your practice.
CBSE SAMPLE PAPERS
Get CBSE sample and question papers of last 7 years with answers to get best practice for your Board Exams
Python String theory and String Programs
Python strings complete theory with illustrations and practice programs for free