-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
124 lines (93 loc) · 3.06 KB
/
main.py
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import random
dices = {
1: (
"┌─────────┐",
"│ │",
"│ ● │",
"│ │",
"└─────────┘",
),
2: (
"┌─────────┐",
"│ ● │",
"│ │",
"│ ● │",
"└─────────┘",
),
3: (
"┌─────────┐",
"│ ● │",
"│ ● │",
"│ ● │",
"└─────────┘",
),
4: (
"┌─────────┐",
"│ ● ● │",
"│ │",
"│ ● ● │",
"└─────────┘",
),
5: (
"┌─────────┐",
"│ ● ● │",
"│ ● │",
"│ ● ● │",
"└─────────┘",
),
6: (
"┌─────────┐",
"│ ● ● │",
"│ ● ● │",
"│ ● ● │",
"└─────────┘",
)
}
def print_dice(dice_value):
dice_art = "\n".join(dices[dice_value])
print(dice_art)
def roll_dice():
return random.randint(1, 6)
def display_menu():
print("Hello! What would you like to do?")
print("a) Roll 1 dice")
print("b) Roll 2 dices")
print("c) Roll n dices")
print("d) Exit")
def main_loop():
while True:
display_menu()
try:
choice = input("Write a, b, c, or d: ").strip().lower()
if choice not in ['a', 'b', 'c', 'd']:
raise ValueError("Invalid choice")
if choice == "a":
rolled_dice = roll_dice()
print_dice(rolled_dice)
print(f"\n You rolled: {rolled_dice}")
elif choice == "b":
print("\n First Dice: \n")
rolled_dice_1 = roll_dice()
print_dice(rolled_dice_1)
print(f"\n You rolled: {rolled_dice_1}")
print(f"\n Second dice: \n")
rolled_dice_2 = roll_dice()
print_dice(rolled_dice_2)
print(f"\n You rolled: {rolled_dice_2}")
print(f"\n Sum of rolls = {rolled_dice_1+rolled_dice_2} \n")
elif choice == "c":
n = int(input("\nHow many dice would you like to roll: "))
rolled_dice_array = []
for i in range(n):
rolled_dice = roll_dice()
print(f"Dice {i+1}:")
print_dice(rolled_dice)
rolled_dice_array.append(rolled_dice)
print(f"your rolls are: {rolled_dice_array}")
print(f"\n Sum of rolls = {sum(rolled_dice_array)}")
elif choice == "d":
print("Thanks for playing!")
break
except ValueError as e:
print(f"Error: {e}. Please enter valid values.\n")
main_loop()