Computer Science, asked by Mister360, 3 months ago

Print this on Python -

0
1 1
2 2 2
3 3 3 3
4 4 4 4 4​

Answers

Answered by atrs7391
18

\textsf{\textbf{\Large{\underline{Question Given:}}}}

\texttt{\large{Print this on Python - }}

\texttt{0}

\texttt{1 1}

\texttt{2 2 2}

\texttt{3 3 3 3}

\texttt{4 4 4 4 4}

\textsf{\textbf{\Large{\underline{Solution:}}}}

\texttt{for i in range(5):}

   \texttt{for j in range(i+1):}

       \texttt{print(i, end=" ")}

   \texttt{print()}

Answered by BrainlyProgrammer
11

Answer:

for I in range(0,5):

‎⠀⠀for j in range(0,I+1):

⠀⠀⠀⠀print(I,end=" ")

⠀⠀⠀⠀#numbers are same in each row so I will print I

⠀⠀print()

One-liner Approach:-

print("\n".join((str(i-1)+" ")*i for I in range(1,6)))

Variable Description:-

  • I,j :- both are loop variable

Always Remember:-

  • By default, loop starts from 0 so you can also write for I in range(5):
  • By default, increment value is 1 so no need to write the increment value in the loop until you want increment value more than 1

Output Attached.

•••♪

Attachments:
Similar questions