Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I'm attempting to get my program to output a square inside of a square using only the functions I've defined, but I can't seem to get everything to line up. I've gotten hollow squares and half-filled squares, but this square inside a square business I can't figure out. Here is the program with example output:

Python
def star():
""" Display a star without the normal new line """
print('*', end='')

def fill():
    """ Display a fill character without the normal new line """
    print('#', end='')

def space():
    """ Display a space without the normal new line """
    print(' ', end='')

def newline():
    """ Display a new line """
    print()

def squareInSquare(outerSize, innerSize):
    """ Display a small square inside a larger square
        - This example has outerSize = 10, innerSize = 4

    print('Outer and inner square of size', outerSize, 'and', innerSize)


What I have tried:

I'm not sure how to approach this, I have learned how to do a hollow square and a filled square, but I'm not sure how to combine them into what this is supposed to be.
Posted
Updated 21-Mar-19 0:55am
v3
Comments
Richard MacCutchan 20-Mar-19 5:16am    
Where is the missing code and the output?
Mohibur Rashid 20-Mar-19 5:59am    
Lost in interpretation!!
Patrice T 20-Mar-19 9:23am    
Complete your code with what you have done so far (single square).

Quote:
I'm not sure how to approach this, I have learned how to do a hollow square and a filled square, but I'm not sure how to combine them into what this is supposed to be.

The job you are learning is about creating algorithms, if we just give you a full solution, you will learn nothing and it will defeat the purpose of homework.
Learning to create algorithms is done with experience and experimenting, you learn by seeing what is working and what is not. This is a first hand process, nobody can do it for you.

Advice: do a set of related exercises more and more complicated.
- print a playfield of 20x30 filed with '.', make it so tiy can change playfield size
- add feature to print a star '*' at given position
- change code for more stars
- add feature to print a square '#' at given position
- change code for more squares
- add feature to print a rectangle '#' at given position
- change code for more rectangles
- add feature to print squares centered on playdield


In order to help you understand why something don't work, learn debugger, it is an incredible learning tool.
Debugger - Wikipedia, the free encyclopedia[^]

Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
Basic Debugging with Visual Studio 2010 - YouTube[^]

27.3. pdb — The Python Debugger — Python 3.6.1 documentation[^]
Debugging in Python | Python Conquers The Universe[^]
pdb – Interactive Debugger - Python Module of the Week[^]

The debugger is here to only show you what your code is doing and your task is to compare with what it should do.
 
Share this answer
 
With two nested loops you may iterate over all the outer square area.

At each position (row, col) check if you are either on the
  • outer square border
or on the
  • inner square border
or, eventually, on the
  • blank area

Print accordingly the (row, col) character.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900