-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dice Rolling Simulator.py
35 lines (27 loc) · 998 Bytes
/
Dice Rolling Simulator.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
import random
def roll_dice():
return random.randint(1, 6)
def main():
print("Welcome to the Dice Rolling Simulator!")
while True:
input("Press Enter to roll the dice.")
try:
result = roll_dice()
print(f"You rolled: {result}")
if random.random() < 0.1:
raise ValueError("Oh! The die fell off the table and into the river...")
while True:
again = input("Roll again? (y/n): ").strip().lower()
if again == 'y':
break
elif again == 'n':
print("Goodbye!")
return
else:
print("Invalid input. Please, enter 'y' or 'n'.")
except ValueError as e:
print(str(e))
print("Unfortunately, you've lost your die in the river. Bye, bye!")
return
if __name__ == "__main__":
main()