I have made a very simple dice game,

How can i output the results of the dice using this format.

Thanks for your time.

==========
|  0     |
|        |
|    0   |
==========

==========
|  0  0  |
|  0  0  |
|  0  0  |
==========
# This is a random dice game.
import random
dice1 = 0
dice2 = 0
def dice_roller():
    print "Dice Roller" 
    print "==============="
    print "1) Enter 1 to roll a six-sided dice"
    
    sum = raw_input("> ")

    if sum == '1':
        dice1 = random.randrange(1, 7)
        dice2 = random.randrange(1, 7)
        print "The first 6-Sided Die Rolled", dice1
        print "=========="
        print "|        |" 
        print "|        |"
        print "|        |"
        print "=========="     
        print "The second 6-Sided Die Rolled", dice2
        print "=========="
        print "|        |" 
        print "|        |"
        print "|        |"
        print "==========" 
        
input = 'C'
while 1:
    if   input == 'Q': break
    elif input == 'C': dice_roller()
    input = raw_input("press c to continue or q to quit: ").upper()
'''
Created on 2011-05-20

@author: Bryn Flewelling
'''
# This is a random dice game.
import random
dice1 = 0
dice2 = 0
def dice_roller():
    print "Dice Roller" 
    print "==============="
    print "1) Enter 1 to roll a six-sided dice"
    
    sum = raw_input("> ")

    if sum == '1':
        dice1 = random.randrange(1, 7)
        dice2 = random.randrange(1, 7)
        print "The first 6-Sided Die Rolled", dice1
        print "The second 6-Sided Die Rolled", dice2
    if dice1 == 1:
        print "=========="
        print "|        |" 
        print "|   0    |"
        print "|        |"
        print "=========="     
    if dice1 == 2:
        print "=========="
        print "| 0      |" 
        print "|        |"
        print "|      0 |"
        print "=========="                                 
    if dice1 == 3:
        print "=========="
        print "| 0      |" 
        print "|   0    |"
        print "|      0 |"
        print "=========="       
    if dice1 == 4:
        print "=========="
        print "| 0    0 |" 
        print "|        |"
        print "| 0    0 |"
        print "=========="  
    if dice1 == 5:
        print "=========="
        print "| 0   0  |" 
        print "|   0    |"
        print "| 0   0  |"
        print "=========="      
    if dice1 == 6:
        print "=========="
        print "| 0    0 |" 
        print "| 0    0 |"
        print "| 0    0 |"
        print "=========="     
        
    if dice2 == 1:
        print "=========="
        print "|        |" 
        print "|   0    |"
        print "|        |"
        print "=========="     
    if dice2 == 2:
        print "=========="
        print "| 0      |" 
        print "|        |"
        print "|      0 |"
        print "=========="                                 
    if dice2 == 3:
        print "=========="
        print "| 0      |" 
        print "|   0    |"
        print "|      0 |"
        print "=========="       
    if dice2 == 4:
        print "=========="
        print "| 0    0 |" 
        print "|        |"
        print "| 0    0 |"
        print "=========="  
    if dice2 == 5:
        print "=========="
        print "| 0   0  |" 
        print "|   0    |"
        print "| 0   0  |"
        print "=========="      
    if dice2 == 6:
        print "=========="
        print "| 0    0 |" 
        print "| 0    0 |"
        print "| 0    0 |"
        print "=========="        
        
input = 'C'
while 1:
    if   input == 'Q': break
    elif input == 'C': dice_roller()
    input = raw_input("press c to continue or q to quit: ").upper()

EDIT: Never mind, you seem to have come up with more or less the same solution on your own while I was working on this. My version's a little more efficient in terms of space, but yours is easier to understand. You might want to look at my version anyway, if only because I used a few techniques you might want to learn.

Probably the easiest solution is to make a set of functions, each on of which prints a given die result, and call them from a jump table to print out the desired result:

def printOne():
    print """
    =========
    |       |
    |   O   |
    |       |
    =========
    """
   
def printTwo():
    print """
    =========
    |  O    |
    |       |
    |    O  |
    =========
    """


def printThree():
    print """
    =========
    | O     |
    |   O   |
    |     O |
    =========
    """
   
def printFour():
    print """
    =========
    | O   O |
    |       |
    | O   O |
    =========
    """
    

def printFive():
    print """
    =========
    | O   O |
    |   O   |
    | O   O |
    =========
    """
    
def printSix():
    print """
    =========
    | O   O |
    | O   O |
    | O   O |
    =========
    """
    

# This is a random dice game.
import random
die1 = 0
die2 = 0

DIE_ROLL = [printOne, printTwo, printThree, printFour, printFive, printSix]

def dice_roller():
    print "Dice Roller"
    print "==============="
    print "1) Enter 1 to roll a six-sided dice"
     
    sum = raw_input("> ")
     
    if sum == '1':
        die1 = random.randrange(1, 7)
        die2 = random.randrange(1, 7)
        print "The first 6-Sided Die Rolled", die1
        printDie = DIE_ROLL[die1 - 1]
        printDie()
        print "The second 6-Sided Die Rolled", die2
        printDie = DIE_ROLL[die2 - 1]
        printDie()
     
input = 'C'
while 1:
    if input == 'Q': break
    elif input == 'C': dice_roller()
    input = raw_input("press c to continue or q to quit: ").upper()
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.