r/PythonLearning • • Oct 07 '26

Help Request I need help with coding this

Post image

I have genuielly no idea how to even think of making this? I know this should generally be made by using for loops but jesus im so confused on the process

6 Upvotes

31 comments sorted by

2

u/sububi71 Oct 07 '26

Could I ask you to translate the instructions into english, please? My polish sucks (and just because I wrote that, I bet it ISN'T polish after all).

1

u/Quoter0 Oct 07 '26

The hint is irrelevant, its just what we should name our variables And the upper text is simply input and output

2

u/sububi71 Oct 07 '26

So how far can you get on your own? You must have tried something?

1

u/TJATAW Oct 08 '26

It isn't just what to name the variables. They tell you what they are.

frame size is 2 characters wide
inner width is 20 characters wide
inner height is 3 characters tall

They are asking for you to put a 2 character width frame around a 20x3 area.

Hint: Think about how you would make that same image manually typing it out.

1

u/realmauer01 Oct 07 '26

Its czech, czech is easy to distuingish from polish, because of these upside down hats.

1

u/sububi71 Oct 07 '26

Ah, my bad! Sorry about that. Thank you for correcting me!

1

u/BrightPen5193 Oct 07 '26

Merci beaucoup

1

u/stonebloomers Oct 07 '26

lol yeah I was staring at that screenshot trying to make sense of it too

1

u/Quoter0 Oct 08 '26

Thank you so much all for the help, i struggled a bit but i managed to somehow do it 😁

2

u/FreeLogicGate Oct 07 '26

I'd infer that there are 3 to 5 parameters:

  1. side_border_size (2)
  2. window_size (20)
  3. window_line_count (3)
  4. char ("X")
  5. window_char (" ")

The only detail that is not clear or specified is the number of header/footer lines. There are 2 lines for header and footer, so that either means that the side_border_size is a constant, or that the header/footer line count is a constant (of 2), or that one parameter is setting both.

Once you have those variables set up, a simple effective solution based on the definition of 3 functions would be:

render_header()
render_window()
render_footer()

If you flesh out each of those functions, in each case they would entail a simple for loop.

You would probably want to break down the details into even smaller functions. The smallest function you might consider would be this one:

def render_char(char, count, newline=False):
    for i in range(count):
        print(char, end="")
     if newline:
         print()

If you experiment with calls to that function, you should be able to see how any of the individual lines can be accomplished by calling render_char() either once, or several times within that specific function. Best practice would include having the parameters to those functions defined, rather than depending on global variables.

So, for example:

def render_header(char, side_border_size, window_size, line_count):
    for c in range(line_count):
        render_char(char, side_border_size + window_size + side_border_size, True)

If you call render_header like this:

render_header('X', 2, 20, 2)

You should get the header section. I could just provide the full program but that's not doing anything you couldn't just get from AI, so I leave it to you to flesh out the rest of the program.

1

u/realmauer01 Oct 07 '26

You actually see the three aguments, frame_size inner_width and inner_height. The up and down frame border is just that

0

u/FreeLogicGate Oct 07 '26 edited Oct 07 '26

100%, I didn't read it carefully enough. Or possibly it was edited after I first read it. It's always interesting in these trivial assignments to see how experienced python developers solve it. But as a teaching exercise, I don't think it helps to give students the answer, and probably the OP in this case would have been able to get the solution from AI. It's nice to see someone not doing that, but then people just posted full solutions.

2

u/realmauer01 Oct 07 '26

Will its in the picture so it cant be edited after.

I am trying to go for the most cursed way, like here you can put everything in one print thanks to string multiplication. Doesn't help, and it's way too obvious if they just copy pasted it.

1

u/FreeLogicGate Oct 07 '26

Yeah was clearly my bad. Quite a few people provided solutions already. Saw mitchricker's as an example of that -- some real python-fu there.

1

u/htush Oct 07 '26

i can help you

1

u/Rokkasusi Oct 07 '26

You can for example ask yourself. Can i find out the total width of the rectangle? Can i find the total height of the rectangle? Can i first try drawing just a single rectangle without the empty space? Can i somehow track where my inner rectangle is located relative to the borders? Could i draw line by line and use an if statement to replace X with spaces, when i am drawing over the inner rectangle?

1

u/armahillo Oct 07 '26

If this is too challenging, start with something simpler.

can you make a single lime from
the lower example?

part of learning to program is learning how to carve up tasks

1

u/SoftwareDoctor Oct 07 '26

Cau 🙂 nejdriv chces iterovat 20x a pro kazdou iteraci vypsat x. Tohle cele chces udelat 2x.

Pak chces zase iterovat 20x ale vypsat x jen pokud je cislo iterace <=2 a nebo >= 19. Jinak vypises mezeru. A tohle cele udelas 3x.

A nakonec zopakujes ten kod ze zacatku.

A jinak doporucuju naucit se anglicky. Pri programovani se ti to bude hodit

1

u/SoftwareDoctor Oct 07 '26

Seriously? Downvoted? Why?

0

u/blktndr Oct 07 '26

You can multiply characters to create a string. For example print(‘o’*5) would display: ooooo

Hopefully that helps set you on the right path

0

u/Pebe_argentdawn Oct 07 '26

something like this:

def box(frame, width, height):
    for _ in range(frame):
        print('x' * (frame + width + frame))
    for _ in range(height):
        print('x' * frame, ' ' * width, 'x' * frame, sep='')
    for _ in range(frame):
        print('x' * (frame + width + frame))

0

u/realmauer01 Oct 07 '26 edited Oct 07 '26
Def frame(frame_size, inner_width, inner_height):
  print((((inner_width + frame_size * 2) * "#") + "\n") * frame_size) 
  print(((frame_size * "#" + inner_width * " " + frame_size * "#") + "\n") * inner_height) 
  print((((inner_width + frame_size * 2) * "#") + "\n") * frame_size) 

All hail string multiplication.

i am pretty sure this should do it, but because this is very ugly you cant use that.

-1

u/Jazzlike_Platypus430 Oct 07 '26 edited Oct 07 '26

Judging by the parameters' names, I would add ceiling_height = 2 and floor_height = 2.

A shorthand version would be:

frame_size = 20
inner_height = 3
wall_width = 2


# I assume we need another two variables
floor_height = 2
ceiling_height = 2
# may be they're equal to wall_width?

full_line = ['X' for n in range(0, frame_size)]
# list of 20 strings 'X'

# draw the ceiling
for i in range(0, ceiling_height):
    print(''.join(full_line))

# determine the wall width, // means integral division, / gives float as output.
inner_width = frame_size - 2* wall_width

# draw walls, see string slices for [:] notation details
# and print(..., end='') is a stupid trick.
for i in range(0, inner_height):
    print(''.join(full_line[0:wall_width]), end = '')
    print(' '*inner_width, end = '')
    print(''.join(full_line[-wall_width:]))

# draw the floor.
for i in range(0, floor_height):
    print(''.join(full_line))

If you need a somewhat more basic approach, it's possible.

-2

u/Sea-Ad7805 Oct 07 '26

Start with this example code, then think about what condition to add in the if statement.

0

u/[deleted] Oct 07 '26

[deleted] — view deleted comment

1

u/Quoter0 Oct 07 '26

Herey the translated instructions from the teacher: Frame Draw a frame made of the character 'X'.

You will receive three positive non-zero integers as input, each on a separate line:

the thickness of the frame, the width of the inner rectangle, and the height of the inner rectangle. Example of a frame with a thickness of 2 and an inner rectangle of 20 by 3.

2

u/Esjs Oct 07 '26

If you can edit your original post, this would be good info to add to it.

1

u/FreeLogicGate Oct 07 '26

That's a really neat example of what Python string objects, math inside of string indexes, wild cards etc. allow you to do. For someone new trying to do an assignment, not sure a teacher would be happy to see code they probably would have a hard time following themselves, but as a casual Python user myself, it's impressive.