1
nRow=int(input("No. of rows: "))
nCol=int(input("No. of columns: "))
ch=input("Which characters? ") 
i=1 
j=1 
while j<=nCol: 
    while i<=nRow: 
        print(ch, end='') 
        i=i+1 
    print(ch, end='') 
    j=j+1

Here I tried my best to make a column and row in while loops, but it just didn't work out. When I input row and column numbers, they just gin one row. Like (Rows:2 Columns:3 characters:a), I expected to get like a table with 2 rows and 3 columns, but I got just - aaaaa.

Jamiu S.
  • 5,257
  • 5
  • 12
  • 34
LordPol
  • 1
  • 2
  • At the bottom of the outer loop set I back to 1. – wwii Feb 05 '23 at 23:03
  • [How to step through Python code to help debug issues?](https://stackoverflow.com/questions/4929251/how-to-step-through-python-code-to-help-debug-issues) If you are using an IDE **now** is a good time to learn its debugging features Or the built-in [Python debugger](https://docs.python.org/3/library/pdb.html). Printing *stuff* at strategic points in your program can help you trace what is or isn't happening. [What is a debugger and how can it help me diagnose problems?](https://stackoverflow.com/questions/25385173/what-is-a-debugger-and-how-can-it-help-me-diagnose-problems) – wwii Feb 05 '23 at 23:04
  • You probably need rows in the outer loop and columns in the inner loop. – wwii Feb 05 '23 at 23:06

2 Answers2

1

You just need to change your loop so you go to new line after every row. You can also use for in range like this

for row in range(nRow):
    for col in range(nCol):
        print(ch, end=' ')
    print()
Nejc
  • 220
  • 1
  • 8
0

Put rows in the outer loop and columns in the inner loop. At the end of each row reset the column counter and print a newline.

while j<=nRow: 
    while i<=nCol: 
        print(ch, end='') 
        i=i+1 
    i = 1
    print() 
    j=j+1
wwii
  • 23,232
  • 7
  • 37
  • 77