-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdice.py
More file actions
42 lines (34 loc) · 1.19 KB
/
dice.py
File metadata and controls
42 lines (34 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# Import necessary modules
import random
from dice_art import DiceArt
# ~~ Rolling the dices ~~
# Return a list of integers with lenght num_dice
def roll_dice(num_dice):
roll_results = []
for _ in range(num_dice):
roll = random.randint(1, 6)
roll_results.append(roll)
return roll_results
# ~~ App's main code block ~~
# Ask the user until provides a valid number or exit the program
def num_dice():
while True:
try:
print("\nType 0 to exit the program.\n")
user_input = int(input("How many dices would you like to roll? "))
# Exit the program if the user inputs 0
if user_input == 0:
print("\nExiting the program. Goodbye!\n")
exit()
# Validate user's input is a number
elif 1 <= user_input:
return user_input
# Raise an error if the input is not a number
except ValueError:
print("\nInvalid input. Please enter a valid number.\n")
# Play the game
while True:
roll = roll_dice(num_dice())
dice_diagram = DiceArt()
result = dice_diagram.generate_dice_faces_diagram(roll)
print(result)