Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
Write a program that prints a box of stars, 4 lines tall and 12 characters wide. The first and last lines are all stars. The two middle lines have a star, ten spaces and a star. Use the repeat sign for the full lines, so that you do not type 12 stars.
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, go through the solution one step at a time, and check each step against your own.
Plan. Four lines. The top and bottom lines are the same, so keep one line in a variable and print it twice.
edge = "*" * 12 makes twelve stars."*" + " " * 10 + "*", which is 12 characters.edge, the middle line twice, and edge.Check. Count the characters of each line: all four have 12. The right edge makes a straight column.
Answer: The program above shows the box.
Log in to join the discussion.
Loading…