[pythonvis] Re: My box drawing program, finally!

  • From: "Jeffrey Thompson" <jthomp@xxxxxxxxxxx>
  • To: <pythonvis@xxxxxxxxxxxxx>
  • Date: Sun, 18 May 2014 17:27:36 -0400

Hi JDog,

        Congratulations!!!

You have done the assignment, and it looks good.

A few helpful suggestions:
I noticed that you had your wile() statement at the end of a line of
assignments.
Was there some reason for this?
It makes it much harder to read, and provides little gain in speed.
I also noticed that you sprinkled a few "empty" print statements before you
printed the box.
It is probably better to do those right before you enter the while loop,
where the sides are printed.
        You might want to add some input validation to insure for example,
that height and width are numbers >= 1.
This should work because Python will cut off any fractions when using values
for weight or height when used to produce strings.

I would also read part of PEP8 where they talk about naming conventions for
variables.
If you incorporate said rules into your programming, it will become a habit,
And then you won't have to try to learn programming style rules when or if
your employer complains and wants you to change all your hard work for free.
Generally the rules are not onerous to implement.

By the way, I also have produced code to print a box.
Unfortunately it uses some programming actions that the students haven't
learned yet.
And it is stuck on an error  that I can't seem to figure out.
So I figure to post it to the list and have our experts take a look at it
for me.

So you seem to be doing better than I am.
Which is a little embarrassing .
But I'll get over it.

        Congratulations Again.I think that you did this fairly quickly
considering you have a life and this is something new for you.

        Jet

-----Original Message-----
From: pythonvis-bounce@xxxxxxxxxxxxx [mailto:pythonvis-bounce@xxxxxxxxxxxxx]
On Behalf Of Jeffrey Turner
Sent: Sunday, May 18, 2014 4:22 PM
To: pythonvis@xxxxxxxxxxxxx
Subject: [pythonvis] My box drawing program, finally!

This is very simple and rudimentary, but I had fun writing it.

JDog

""" This program will draw a box according to width and height specs
provided by the user"""

print "I will now draw a box for you, with pretty plus signs for the
corners, "
print "dashes for the top and bottom, and bars for the sides."
print
width = input("How wide would you like the box to be?")
print
height = input("How high would you like the box to be?")
corner = "+"
dashes = width*"-"
indent = " "*3
bar = "|"
spaces = " "*width
print
top = bottom = indent+corner+dashes+corner
print top 
sides = indent+bar+spaces+bar
count = height
while count >= 1:
  print sides
  count = count-1
print bottom
print
print "OK, here is your", width, "by", height, "box."print "Thank you for
doing business with the marvelous JDog."



Other related posts: