85.7k views
5 votes
Write code which prints every number from 1 to 20 a number of times equal to the number itself (e.G. One 1, two 2's...). Every individual number printed should be separated by a space, and there should be a new line each time the number changes. You should use nested loops to produce your output (it will result in far less code).

User Octoshape
by
5.7k points

1 Answer

4 votes

Answer:

Answered in Python

for i in range(21):

for j in range(i):

print(i, end=' ')

print(" ")

Step-by-step explanation:

This iteration iterates from 1 to 20

for i in range(21):

This iteration iterates from 1 to current number

for j in range(i):

This prints the current number in the a number of times equal to itself

print(i, end=' ')

This enables printing on new line

print(" ")

User Tarrell
by
5.8k points