Correct this python cøde to print the output as shown in the attachment:
L = [ "P", "Y", "T", "H", "O", "N" ]
a = 0
for j in range (1, 7):
for i in range (j):
print(L[a], end = " ")
a = a + 1
print()
Attachments:

Answers
Answered by
1
Explanation:
Sodium carbonate is a chemical compound with the molecular formula Na2CO3.
Answered by
3
L = [ "P", "Y", "T", "H", "O", "N" ]
a = 0
for j in range (1, 7):
for i in range (j):
print(L[a], end = " ")
a = a + 1
print()
L = ["P", "Y", "T", "H", "O", "N"]
for j in range (1, 7):
a=0
for i in range (j):
print(L[a], end = " ")
a = a + 1
print()
- Indentation not given. Its mandatory to give indentation.
- On moving to next row, you have to start from first element of list 'L'. So, for that, you have to change the value of 'a' to 0 otherwise IndexError will occur. So, here, I wrote a = 0 before the starting of inner loop.
You can also use these approaches to solve this problem.
1. List Slicing.
L = [ "P", "Y", "T", "H", "O", "N" ]
for j in range (1, 7):
print(*L[:j],sep=" ")
See the attachments for output.
Attachments:


Similar questions