Python Forum
Create a program that draws a box
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Create a program that draws a box
#1
Detailed description of your problem, including steps to reproduce it:
This is for a homework assignment that I have already missed the deadline for, however I still feel compelled to complete the problem. We were asked to do the following:

https://imgur.com/CeenLOK

We were given this bit of info to help:

https://imgur.com/tUOZSiZ

****Mind you we just learned while loops, so we are expected to complete this problem using a while loop.

What steps have you tried? What was the outcome?
width = int(input("Enter the width of your box: "))
print()
length = int(input("Enter the length of your box: "))
print()
   
border = "*" * width  
print(border)
border = "*" + width * " " + "*"


while length < width:
    print(border)
    length = length + 1 

print("*" * width)


Screenshot of output: https://imgur.com/XqrMZmN

[b]System info, python version, operating system, etc.[/b: Python 3.5, Windows 10

PLEASE HELP Wall
Reply
#2
Please use code tags on future posts see: BBCODE
I added them for you this time.
Reply
#3
Sorry about that. I'll be sure to review the appropriate formatting.
Reply
#4
look at line 8. if you want width n, what is the length of the string you print?
Reply
#5
Any chance you could elaborate any further? I seem to be struggling with the concept of loops. I understand them to a point, but I keep racking my brain and can't seem to get a full understanding. I asked my teacher for a hint as well, and her response was this:

"Take another look at your condition. The answer is there. Should you be comparing width vs length? Or should there be some other variable that keeps track of where you are at in the loop? "

I feel like I'm so close, but I just cant seem to get it. The worst part is I know its staring me right in the face and I'm going to feel ignorant when I finally figure it out.
Reply
#6
Your teacher went one step further... There is problem even before that.
Let's ask the question in a different way - what is the width and height of your rectangle and what it should be. I said line 8 because it is easier to spot the problem there. One more hint - how many characters you print on line 6-7? Then on next step think how many times you want to execute loop body and how many times it is actually executed ( that is your teacher's hint/question)
Reply
#7
Finally figured it out!

https://gist.github.com/xClarkKenx/8a0a1...3465800a6b

width = int(input("Enter the width of your box: "))
print()
length = int(input("Enter the length of your box: "))
print()


top = "*" * width
s = (" " * (width - 2)) 
border = "*" + s + "*"

x = length
y = 2

print(top)

while (y != x):
    print(border)
    y = y + 1

print(top)   
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  how do i create this program alexisyzr 3 6,425 Nov-07-2018, 11:51 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020