Skip to content

Commit 0654b51

Browse files
authored
dice_rolling.py
This code simulates the "Rolling of a die/pair of dice", and displays the output of the face.
1 parent ed185d1 commit 0654b51

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

dice_rolling.py

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import random
2+
3+
def single_die():
4+
'''
5+
This function gives a random value of the die (1-6)
6+
'''
7+
8+
die_roll = random.randint(1,6)
9+
return die_roll
10+
11+
def double_dice():
12+
'''
13+
This function uses the previous function (single_die()) twice
14+
'''
15+
16+
val_1 = single_die()
17+
val_2 = single_die()
18+
return val_1, val_2
19+
20+
num1, num2 = double_dice()
21+
22+
sum_faces = n1 + n2
23+
24+
print("\t\t\tMENU")
25+
print("\n1. One Die\n2. Two Dice\n")
26+
27+
ans = 'y'
28+
while ans.lower() == 'y':
29+
option = int(input("Enter your choice"))
30+
31+
if option == 1:
32+
print("The value of the face is: ",single_die())
33+
34+
elif option == 2:
35+
print("The value of the first face is: ",num1, "\nand the value of the second face is: ",num2)
36+
print("The sum of the faces is: ",sum_faces)
37+
38+
ans = input("Do you wish to continue?(Y/n): ")

0 commit comments

Comments
 (0)