On Fri, Aug 8, 2014 at 4:50 AM, Greg Markham <greg.mark...@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_1 = """ > .-----. > | | > | o | > | | > `-----'""" > > die_2 = """ > .-----. > |o | > | | > | o| > `-----'""" > > print(die_1, die_2) > > > So, how would I get this to display horizontally? > > Like so... > .-----. .-----. > | | |o | > | o | | | > | | | o| > `-----' `-----' >
This isn't so easy because as you print the first die, your cursor ends up at the bottom of its display. There is a module called curses which lets you manipulate the terminal. It has functions to get the x,y position on the screen, and to set it (i. e. move the cursor). You might want to play with that. If you want to get your feet wet with unicode, you could use the dice characters (see: http://www.unicode.org/charts/PDF/U2600.pdf). >>> dice_1 = '\u2680' >>> print (dice_1) ⚀ >>> print (dice_1, dice_2) ⚀ ⚁ They are pretty small. > Thanks, > > Greg > > _______________________________________________ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor > -- Joel Goldstick http://joelgoldstick.com _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor