[Tutor] Fwd: Printing multi-line variables horizontally
Chris “Kwpolska” Warrick
kwpolska at gmail.com
Sat Aug 9 12:39:37 CEST 2014
It looks ilke this WONDERFUL mailing list which does not do something
as basic as a sane Reply-to header made me send a response to the OP
only. Here it is again:
---------- Forwarded message ----------
From: Chris “Kwpolska” Warrick <kwpolska at gmail.com>
Date: Fri, Aug 8, 2014 at 7:36 PM
Subject: Re: [Tutor] Printing multi-line variables horizontally
To: Greg Markham <greg.markham at gmail.com>
On Aug 8, 2014 7:22 PM, "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:
>
>
> # Craps Roller
> # Demonstrates random number generation
>
> import random
>
> # generate random numbers 1 - 6
> die1 = random.randint(1, 6)
> die2 = random.randrange(6) + 1
>
> total = die1 + die2
>
> print("You rolled a", die1, "and a", die2, "for a total of", total)
>
> input("\n\nPress the enter key to exit.")
>
>
> I wanted to make it a little more interesting by using ascii art representations of the six die. When printing, however, they do so vertically and not horizontally. Here's a snippet of the code:
>
>
>
> die_2 = """
> .-----.
> |o |
> | |
> | o|
> `-----'"""
>
> print(die_1, die_2)
>
>
> So, how would I get this to display horizontally?
>
> Like so...
> .-----. .-----.
> | | |o |
> | o | | |
> | | | o|
> `-----' `-----'
>
> Thanks,
>
> Greg
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
You would need to do some extra work. Specifically, you must split the
string into lines, and print them side-by-side and line-by-line. Like
this:
die_1 = [
".-----.",
"|o |",
"| |",
"| o|",
"`-----'",
]
die_2 = [
".-----.",
"| |",
"| o |",
"| |",
"`-----'",
]
for l, r in zip(die_1, die_2):
print(l, r)
--
Chris “Kwpolska” Warrick <http://chriswarrick.com/>
Sent from my SGS3.
More information about the Tutor
mailing list