-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdice_roller.py
More file actions
31 lines (27 loc) 路 967 Bytes
/
Copy pathdice_roller.py
File metadata and controls
31 lines (27 loc) 路 967 Bytes
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
import random
def roll_dice(num_dice, num_sides):
results = []
for _ in range(num_dice):
result = random.randint(1, num_sides)
results.append(result)
return results
def main():
print("馃幉 Dice Roller App 馃幉")
while True:
try:
num_dice = int(input("How many dice would you like to roll? "))
num_sides = int(input("How many sides per die? (e.g. 6 for standard) "))
if num_dice < 1 or num_sides < 2:
print("Please enter valid positive numbers.")
continue
rolls = roll_dice(num_dice, num_sides)
print(f"Results: {rolls}")
except ValueError:
print("鈿狅笍 Invalid input. Please enter whole numbers.")
continue
again = input("Roll again? (y/n): ").lower()
if again != "y":
print("馃憢 Thanks for rolling!")
break
if __name__ == "__main__":
main()