[Tutor] Printing multi-line variables horizontally

Danny Yoo dyoo at hashcollision.org
Fri Aug 8 20:03:22 CEST 2014


On Fri, Aug 8, 2014 at 1:50 AM, Greg Markham <greg.markham at gmail.com> wrote:
> Hello,
>
> Python novice back again.  :)  I'm making progress in my learning process,
> but struggling whenever attempting to creatively go beyond what's required
> in the various chapter assignments.  For example, there's a simple random
> die roller program that looks like the following:


Hi Greg,

It looks like each die has the same dimensions.  What I mean is that
it looks like each "die" has the same number of lines, and each line
is the same width.  Is that assumption correct?  If so, then that
might simplify matters for you.  It sounds like you're trying to build
a "row" of dice.  To do so, you might be able to loop over the lines
of both dice at once to get the composite image.

That is:

    row[0] = die_1_lines[0] + die_2_lines[0]
    row[1] = die_1_lines[1] + die_2_lines[1]
    ...

where we take horizontal slices of each dice and stick them side by
side.  To make this work, we need to be able to get at individual
lines.  To break a string into a list of lines, see

    https://docs.python.org/2/library/stdtypes.html#str.splitlines


More information about the Tutor mailing list