Hi
This is my first ever python assignment and I am sort of stuck...:'(

I need to fit a text inside this box (textwrap). I think I figured out the code for the insert, but I also have to make the box with two whitespaces on each side of the inserted text.

Any ideas ?? I just need a push in the right direction.


import textwrap
def format_postcard(story, width, depth):
wrap_story = textwrap.wrap(story, width)
if story >= 25:
print wrap_story
else:
print 'sorry, the synopsis is too long.'

+---------------+
| cccccccccccc |
| cccccccccccc |
| cccccccccccc |
| cccccccccccc | |
+---------------+

Thank you

Isa

Take a look at the textwrap docs here http://docs.python.org/lib/module-textwrap.html You should be able to use initial_indent and subsequent_indent for the left side spaces. For spaces on the right side, reducing width by 2 should get that, but I have never used textwrap. Also, it is not meant to be a total solution so you may have to write your own.

What is depth?

And you're trying to insert a paragraph into the 'postcard'?

the first thing you should fix is that textwrap.wrap returns a list, so print wrap_story would return something looking like this:

which is probably not what you want in your postcard, right?

Also it appears that this part of your code should be "<", not ">"

if story <= 25:
   print wrap_story
else:
   print 'sorry, the synopsis is too long.'

Doesn't

story <= 25

say story less than or equal to 25?

I think she wants story more than or equal to 25...

I may be totally insane.

Note the else: "print 'sorry, the synopsis is too long.". That is what I was going on, but the OP will have to decide.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.