for a in range ( 4,17):
for b in range (a):
print( a,end=' ')
print()
Answers
Answer:
> 4 4 4 4 5 5 5 5 5 6 6 6 6 6 6 7 7 7 7 7 7 7 8 8 8 8 8 8 8 8 9 9 9 9 9 9 9 9 9 10 10 10 10 10 10 10 10 10 10 11 11 11 11 11 11 11 11 11 11 11 12 12 12 12 12 12 12 12 12 12 12 12 13 13 13 13 13 13 13 13 13 13 13 13 13 14 14 14 14 14 14 14 14 14 14 14 14 14 14 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16
Explanation:
First for loop, loops a between number 4 to 17 (not including 17), and second for loop, loops b between 0 to 4. The print statement prints out 'a', so when a = 4, the second loop, loops 4 times, so the number is printed 4 times, when a = 5, the second loop, loops 5 times, so the number is printed 5 times, and so on for the other numbers, until 16, the first loop ends.
Corrected Códe:-
for a in range ( 4,17):
for b in range (a):
print( a,end=' ')
print()
Output:-
- Given in attachment
Explanation:-
- Outer loop runs from 4 to 16 (17 is not included)
- inner loop runs from 1 to 1 less than the value of outer loop
- value of outer loop is printed with spaces
- once inner loop becomes equal to outer loop, inner loop terminates
- print() will move the cursor to next line.
- Same process repeats until outer loop becomes 17
- once the outer loop becomes 17, loop terminates.
- Hence, the program ends :)