Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

How I can get this output?

+1 vote
asked Oct 28, 2019 by Cristina

I have a Python problem here. Write the code using while loops in order to print the following:

1

1 2

1 2 3

1 2 3 4

5 Answers

0 votes
answered Oct 28, 2019 by gameforcer (2,990 points)

It's awkward doing this using while loops but here you go:

c = 1
lst = [c]

while c <= 4:
    cnt = 0
    while cnt < len(lst):
        print(lst[cnt], end=' ')
        cnt += 1
    print()
    c += 1
    lst.append(c)

–1 vote
answered Oct 29, 2019 by anonymous
/******************************************************************************

                              Online C++ Compiler.

               Code, Compile, Run and Debug C++ program online.

Write your code in this editor and press "Run" button to compile and execute it.

print

1

1 2

1 2 3

1 2 3 4

*******************************************************************************/

#include <iostream>

using namespace std;

int resolve (4);

int main()

{

  int resolve[4] = {1,2,3,4};

  for (int i=0; i<4; ++i) {

        cout << resolve[i] << "  \n";

        if (resolve[i] == 4) break;

    int x = resolve[i];

    for (int j=0 ; j<4; j++) {

       

        if (x==j) break;

        cout << resolve[j] << "  ";

       

    }

  }

}
0 votes
answered Nov 2, 2019 by ROSHAN SHANDRES C (250 points)
CONVERT THIS "C" SOURCE CODE TO "PYTHON"

void main ()
{
  int i=1,j;
  while(i<5)
  {
    j=1;  
    while(j<=i)
    {
        printf("%d ",j);
        j++;
    }
    printf("\n");
   i++;
  }
}
0 votes
answered Nov 7, 2019 by dheeraj (1,090 points)
a=int(input ('enter the number upto you want))
for i in range(1,a+1):
        for j in range (1,i+1):
             print (j,end='')
        print ()
0 votes
answered Nov 7, 2019 by dheeraj (1,090 points)
a=int(input ('enter the number upto you want))
for i in range(1,a+1):
        for j in range (1,i+1):
             print (j,end='')
        print ()

output.                                            @python 3.7.2
enter the number upto you want 5
1
12
123
1234
12345
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...