Dice Rolling Simulator Program in Python


import random

dice_drawings = {
    1:   ("┌─────────┐",
          "│         │",
          "│    ●    │",
          "│         │",
          "└─────────┘"),
    2:   ("┌─────────┐",
          "│  ●      │",
          "│         │",
          "│      ●  │",
          "└─────────┘"),
    3:   ("┌─────────┐",
          "│  ●      │",
          "│    ●    │",
          "│      ●  │",
          "└─────────┘"),
    4:   ("┌─────────┐",
          "│  ●   ●  │",
          "│         │",
          "│  ●   ●  │",
          "└─────────┘"),
    5:   ("┌─────────┐",
          "│  ●   ●  │",
          "│    ●    │",
          "│  ●   ●  │",
          "└─────────┘"),
    6:   ("┌─────────┐",
          "│  ●   ●  │",
          "│  ●   ●  │",
          "│  ●   ●  │",
          "└─────────┘")
}

# rollit = input("Roll the dice? (y/N): ").lower()
    
# while rollit == "y":
    
#     dice1 = random.randint(1,6)
#     dice2 = random.randint(1,6)
    
#     print("Dices rolled. Results are {} and {}.".format(dice1, dice2))
    
#     print("\n".join(dice_drawings[dice1]))
#     print("\n".join(dice_drawings[dice2]))

#     rollit = input("Roll the dice? (y/N): ").lower()

######################################################

# for more than 2 dices, use the following
no_of_rolls = int(input("How many dices do you want to roll? "))
rolls_results = []
for i in range(no_of_rolls):
    rolls_results.append(random.randint(1,6))
print("The dice results are",rolls_results)

# for i in rolls_results:
#     print("\n".join(dice_drawings[i]))

# the above 2 lines can be replace with the following, result will be the same
for i in range(no_of_rolls):
    for art in dice_drawings.get(rolls_results[i]):
        print(art)

# to print the dice drawings horizontally, use the following     
# for line in range(5):
#     for rolls in rolls_results:
#         print(dice_drawings[rolls][line], end="")
#     print()
   

    

Comments

Popular posts from this blog

Quotation marks to wrap an element in HTML

The Basic Structure of a Full-Stack Web App

Unlocking Web Design: A Guide to Mastering CSS Layout Modes