Question

Using for loops create a method for each of the following patterns. Each method should take...

Using for loops create a method for each of the following patterns. Each method should take an integer parameter “n” and print an n × n square with the given pattern.

XXXX
XOOX
XOOX
XXXX

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is code in python:

def pattern(n):

for i in range(0,n):

for j in range(0,n):

if(i == 0 or i == n-1 or j == 0 or j == n - 1):

print("X",end='')

else:

print("0",end='')

print() # new line

pattern(4)

Output:

Add a comment
Know the answer?
Add Answer to:
Using for loops create a method for each of the following patterns. Each method should take...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT