Question

Nested squares in python programming

(f) Nested squares with outer side length of 2*N+1 and each inner square spaced as shown. Note that any two s, each from a

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

python code:

def nested_squares(N):
n = 2*N+1

# no of rows in square
for i in range(1,n+1):
  
# no of columns in square
for j in range(1,n+1):
  
# print the star in square
if ((i == 1 or i == n or j == 1 or j == n) or
(i >= 3 and i <= n - 2 and j >= 3 and j <= n - 2) and
(i == 3 or i == n - 2 or j == 3 or j == n - 2) or (i== (n+1)/2 and j== (n+1)/2)):
  
print("*",end="") # print star
  
else:
  
print(" ",end="") # print space
  
print()
  
  
# call the function
nested_squares(4)

code and output:

Eile Edit Format Run Options Window def nested squares (N) 2*N+1 n = # no of rows in 3quare for i in range (i,n+1): # no of c

//for any clarification, please do comments. if you found this solution useful, please give me thumbs up.

Add a comment
Know the answer?
Add Answer to:
Nested squares in python programming (f) "Nested squares" with outer side length of 2*N+1 and each inner square spaced as shown. Note that any two s, each from a different square, are separat...
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
  • [EC1-1] (patterns3.py) More fun with * patterns... Each of these is worth 0.25 points, except for...

    [EC1-1] (patterns3.py) More fun with * patterns... Each of these is worth 0.25 points, except for (f) and (g), which are worth 1 point each. Write a program that reads an int N >= 0, then prints out each of the following patterns of *. Here, you may use the * repetition operator, if you wish. Also, each pattern must be output via a single function call to the given named function with single parameter N. Examples for N==4 follow,...

  • The Box Problem Take an 8% x 11 sheet of paper and cut out 4 congruent squares (one from each corner) as shown belo...

    The Box Problem Take an 8% x 11 sheet of paper and cut out 4 congruent squares (one from each corner) as shown below on the left. This creates a net for an open-topped box (rectangular prism) which can be folded up as shown on the right. We're going to use our box to carry as many M & M's as possible. If the side-length of each cut-out square is 1 inch, then the box created will have dimensions 1...

  • A loop of wire is in the shape of two concentric semicircles as shown. (Figure 1) The inner circle has radius a; the ou...

    A loop of wire is in the shape of two concentric semicircles as shown. (Figure 1) The inner circle has radius a; the outer circle has radius b. A current I flows clockwise through the outer wire and counterclockwise through the inner wire. What is the direction of the magnetic field at the center of the semicircles? Question 4 A loop of wire is in the shape of two concentric semicircles as shown. (Eigure 1) The inner circle has radius...

  • p o 1. The grid shown below is a 2-dimensional Euclidean plane where each square has a side o length 1. Eight vertices are given of a complete graph with the edges implicitly defined by the veen...

    p o 1. The grid shown below is a 2-dimensional Euclidean plane where each square has a side o length 1. Eight vertices are given of a complete graph with the edges implicitly defined by the veen vertices. The cost of each edge is the standard Euclidean distance between its end vertices. Run Approx-TSP-Tour on this graph and show the output tour and its total cost. p o 1. The grid shown below is a 2-dimensional Euclidean plane where each...

  • Question A matrix of dimensions m × n (an m-by-n matrix) is an ordered collection of m × n elemen...

    Question A matrix of dimensions m × n (an m-by-n matrix) is an ordered collection of m × n elements. which are called eernents (or components). The elements of an (m × n)-dimensional matrix A are denoted as a,, where 1im and1 S, symbolically, written as, A-a(1,1) S (i.j) S(m, ). Written in the familiar notation: 01,1 am Gm,n A3×3matrix The horizontal and vertical lines of entries in a matrix are called rows and columns, respectively A matrix with the...

  • Consider a cylindrical capacitor like that shown in Fig. 24.6. Let d = rb − ra...

    Consider a cylindrical capacitor like that shown in Fig. 24.6. Let d = rb − ra be the spacing between the inner and outer conductors. (a) Let the radii of the two conductors be only slightly different, so that d << ra. Show that the result derived in Example 24.4 (Section 24.1) for the capacitance of a cylindrical capacitor then reduces to Eq. (24.2), the equation for the capacitance of a parallel-plate capacitor, with A being the surface area of...

  • 2. If two different compounds have the same Rr value, how might they be identified using paper chromatography?...

    2. If two different compounds have the same Rr value, how might they be identified using paper chromatography? 3. Why is it important to keep the spots on the paper as small as possible? 4. If the solvent pool at the bottom of the beaker touched the spots on the 1.5cm line, what would happen to the spots? How would you address this error? 5. If you were teaching a student how to do paper chromatography, what three pieces of...

  • 18.1 Lab Lesson 11 (Part 1 of 1) Part of lab lesson 11 There in one...

    18.1 Lab Lesson 11 (Part 1 of 1) Part of lab lesson 11 There in one part to lab lesson 11. The entire lab will be worth 100 points. Lab lesson 11 part 1 is worth 100 points For part 1 you will have 80 points if you enter the program and successfully run the program tests. An additional 20 points will be based on the style and formatting of your C++ code. Style points The 20 points for coding...

  • A. Introduction and Objective Every test has at least two sources of variation that affect the results of...

    A. Introduction and Objective Every test has at least two sources of variation that affect the results of the test. The first source of variation is due to the experimental procedure, such as using two different testing machines that have different calibrations, or different observers reading the same equipment differently. This type of variation is often called the experimental error The second source of variation is inherent in the specimens (or sample population) themselves. In other words, no two specimens...

  • Help with Data Science python notebook, Question 1 Create a function called vowel_parse() that takes a...

    Help with Data Science python notebook, Question 1 Create a function called vowel_parse() that takes a single string as input. This string is the name of the input directory. It returns a dictionary. This dictionary has keys that are the names of the individual input files. The dictionary values are the number of words in that file that have adjacent vowels ('aa', 'ae', 'oo', 'ia', etc.). Use a regular expression to find these, do not hard code every possible combination...

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