Q. Write programs using nested loops to produce the following pattern:

(i)
A
A B
A B C
A B C D
A B C D E
A B C D E F

(ii)

0
22
444
8888


You can understand by Watching video :-



Answer :-

(i).

for i in range(6):
      for j in range(6):
            if i >= j :
                  print(chr(65+j)+" ",end="")
      print()

(ii).

for i in range(4):
    if i == 0 :
            print(0)
            continue
    for j in range(i+1):
        print(str(2**i),end="")
    print()

Alternate program :-

for i in range(4):
      if i == 0 :
            print(0)
      else:
            print(str(2**i)*(i+1) )




8 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

  1. Bro second one is not loop. Loop is when you put a loop in another loop like for or while but you have used if else which is conditional

    ReplyDelete
  2. Yeah even question ask for nested loop

    ReplyDelete
  3. the second one is not correct. bruh pls correct it and also there are four questions but u have solutions to only two of them also the second one is wrong. pls give the solutions to the other two ones and check the second one

    ReplyDelete
    Replies
    1. Second is coreect please check it again and tell me other two questions.

      Delete
  4. Replies
    1. Why you want Maja in Computer science 😁😁??

      Delete

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post