lundi 20 décembre 2021

How to form a pattern of X in the format of a box but instead every line the position of X alternates?

if anybody could help me with this problem it would be a great help. SO the task at hand is summarised into this:

Write a function named diagonal(n) that takes a positive integer parameter ‘n’ and that prints an n × n box pattern with Xs on all four sides and on the main diagonal. The illustration shows the desired output for n = 9.

XXXXXXXXX

XX X

X X X

X X X

X X X

X X X

X X X

X XX

XXXXXXXXX

i have little to no idea how to edit this question so it looks proper when I publish it.

So my progress so far is:

def diagonal(n):

for row in range(n):

    for col in range(1):

        print("X", end="")

    print()

diagonal(7)

If somebody could help me out, I would appreciate it big time. Thanks

Aucun commentaire:

Enregistrer un commentaire