-
Notifications
You must be signed in to change notification settings - Fork 135
Expand file tree
/
Copy pathDice_Rolling_sim.py
More file actions
36 lines (28 loc) · 853 Bytes
/
Dice_Rolling_sim.py
File metadata and controls
36 lines (28 loc) · 853 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
32
33
34
35
36
import random
from collections import defaultdict
def roll_dice():
return random.randint(1,6)
#Stores how many times a face appears
face_count= defaultdict(int)
total_roll =0
#Ask user for input
while True:
user_input= input("\n Roll a dice? (yes or no):\n")
if user_input== "yes":
result= roll_dice()
face_count[result] += 1 #Adds 1 to the count of your result (face)
total_roll +=1
print(f"You rolled a {result}")
elif user_input== "no":
#provides the game summary
print("\n🎯 Roll Summary:")
print(f"Total rolls: {total_roll}")
#Shows how many times each face came up
for face in range(1, 7):
count = face_count[face]
print(f"Face {face}: {count}")
print("BYE!")
break
else:
print("Enter yes or no")
continue