Home > OS >  why doesnt this code print a full V pattern?
why doesnt this code print a full V pattern?

Time:03-30

I dont see why this isnt working. It should print a full V but it doesnt it stops printing at col 8

for row in range(5):
    for col in range(8):
        if row == col or row   col == 9:
            print("*",end='')
        else:
            print(' ',end='')
    print()

CodePudding user response:

You didn't provide a big enough column number. 8 is exactly what you passed to the range of the second loop. However, your 'V' needs as many columns as two times the number of rows.

for row in range(5):
    for col in range(10):
        if row == col or row   col == 9:
            print("*",end='')
        else:
            print(' ',end='')
    print()

CodePudding user response:

change col in range(8) to range(10) you will have full V. Because a full V need 10 column This is the full code

for row in range(5):
    for col in range(10):
        if row == col or row   col == 9:
            print("*",end='')
        else:
            print(' ',end='')
    print()
  • Related