logo CodeStepByStep logo

xo

Language/Type: Python loops if/else

Write a function named xo that accepts an integer size as a parameter and prints a square of size by size characters, where all characters are "o" except that an "x" pattern of "x" characters has been drawn from the corners of the square. In other words, on the first line, the first and last characters are "x"; on the second line, the second and second-from-last characters are "x"; and so on. If 0 or less is passed for the size, no output should be produced.

The following table lists some calls to your function and their expected output:

Call xo(5) xo(8)
Output
xooox
oxoxo
ooxoo
oxoxo
xooox
xoooooox
oxooooxo
ooxooxoo
oooxxooo
oooxxooo
ooxooxoo
oxooooxo
xoooooox
Function: Write a Python function as described, not a complete program.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.