Skip to content

PRO TIP Block youtube.com at the DNS level โ€” Pi-hole, NextDNS or your hosts file โ€” but allow youtube-nocookie.com and i.ytimg.com. These tutorials keep playing; the rabbit hole does not.

Learning without distractions

Code a dice roller program in 10 minutes! ๐ŸŽฒ

104.2K views on YouTube

#python #tutorial #course

# Here are the Unicode characters I use for drawing the dice.
# Youtube has strange spacing, so the ASCII art looks warped in the description.
# It should still work if you copy and paste it into PyCharm.

# โ— โ”Œ โ”€ โ” โ”‚ โ”” โ”˜

import random

dice_art = {
1: (“โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ””,
“โ”‚ โ”‚”,
“โ”‚ โ— โ”‚”,
“โ”‚ โ”‚”,
“โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜”),
2: (“โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ””,
“โ”‚ โ— โ”‚”,
“โ”‚ โ”‚”,
“โ”‚ โ— โ”‚”,
“โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜”),
3: (“โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ””,
“โ”‚ โ— โ”‚”,
“โ”‚ โ— โ”‚”,
“โ”‚ โ— โ”‚”,
“โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜”),
4: (“โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ””,
“โ”‚ โ— โ— โ”‚”,
“โ”‚ โ”‚”,
“โ”‚ โ— โ— โ”‚”,
“โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜”),
5: (“โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ””,
“โ”‚ โ— โ— โ”‚”,
“โ”‚ โ— โ”‚”,
“โ”‚ โ— โ— โ”‚”,
“โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜”),
6: (“โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ””,
“โ”‚ โ— โ— โ”‚”,
“โ”‚ โ— โ— โ”‚”,
“โ”‚ โ— โ— โ”‚”,
“โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜”)
}

dice = []
total = 0
num_of_dice = int(input(“How many dice?: “))

for die in range(num_of_dice):
dice.append(random.randint(1, 6))

# PRINT VERTICALLY
# for die in range(num_of_dice):
# for line in dice_art.get(dice[die]):
# print(line)

# PRINT HORIZONTALLY
for line in range(5):
for die in dice:
print(dice_art.get(die)[line], end=””)
print()

for die in dice:
total += die
print(f”total: {total}”)