0

So i was bored and made random stuff:

rows = int(input("How many rows? "))
columns = int(input("How many columns? "))
symbol = input("What symbol? (Symbol can only be one.): ")
if len(symbol) > 1:
    print("Symbol length can only be one")

for i in range(rows):
    for j in range(columns):
        print(symbol)

But, when i run the code and i made rows = 5 and columns = 6 it doesn't work. The result comes like this:

@
@
@
@
@
@
@
@
@
@
@
@
@
@
@
@
@
@
@
@
@
@
@
@
@
@
@
@
@
@

i want to format to:

@@@@@@
@@@@@@
@@@@@@
@@@@@@
@@@@@@

I even tried print(symbol, end="") but the result comes out like this:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

I don't know how or why this happens and i may sound dumb, but this is my first time using nested loops.

Rydex
  • 395
  • 1
  • 3
  • 9

2 Answers2

2

You forgot to move to the next line when you tried print(symbol, end=""):

for i in range(rows):
    for j in range(columns):
        print(symbol, end="")
    print()  # <-- missing piece

However, you could also just use print(symbol*columns):

for i in range(rows):
    print(symbol*columns)

PS. You also do not abort your script when len(symbol) > 1. It will print Symbol length can only be one and then just continue.

Thomas
  • 8,357
  • 15
  • 45
  • 81
1
rows = int(input("How many rows? "))
    columns = int(input("How many columns? "))
    symbol = input("What symbol? (Symbol can only be one.): ")
    if len(symbol) > 1:
        print("Symbol length can only be one")

    for i in range(rows):

        for j in range(columns):

            print(symbol, end='')
        print('') # you needed to add this