Skip to content

Commit 5582ed4

Browse files
authored
Add files via upload
1 parent f384058 commit 5582ed4

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

Roll-Dice-Game/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Roll dice game
2+
-------------------------------------------
3+
## question
4+
5+
### You roll two six-sided dice, each with faces containing one, two, three, four, five
6+
### and six spots, respectively. When the dice come to rest, the sum of the spots on the
7+
### two upward faces is calculated. If the sum is 7 or 11 on the first roll, you win. Ifthe sum is 2, 3 or 12 on the first ### roll (called “craps”), you lose (i.e., the “house”wins). If the sum is 4, 5, 6, 8, 9 or 10 on the first roll, that sum ### becomes your
8+
### “point.” To win, you must continue rolling the dice until you “make your point”
9+
### (i.e., roll that same point value). You lose by rolling a 7 before making your point.
10+
11+
## -> From deitel series book <-

Roll-Dice-Game/Roll-dice.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import random
2+
import sys
3+
4+
random.seed()
5+
6+
flag = 0
7+
points = 0
8+
9+
# this function just Rrtuen Two random number in a tuple between 1 to 6
10+
def drop_dice():
11+
one = random.randrange(1,7)
12+
two = random.randrange(1,7)
13+
print(f"Player Got {one} and {two}")
14+
print(f"Sum is {one + two}")
15+
return (one,two)
16+
17+
# this function drop Dice for first time
18+
def first_drop():
19+
flag = 1
20+
dice = drop_dice()
21+
# unpack tuple
22+
one,two = dice
23+
# if sum of Dice is 7 or 11 Player win
24+
if (one + two in [7,11]):
25+
print("Player Win in First Round!")
26+
sys.exit(0)
27+
# else if sum of dice is 12 or 3 or 2 player lose
28+
elif(one+two in [12,3,2]):
29+
print("Player Lose! in First Round!")
30+
sys.exit(1)
31+
# else sum of dice is in [10,9,8,6,5,4] we set sum of dice to player point
32+
elif(one+two in [10,9,8,6,5,4]):
33+
points = one+two
34+
print(f"POINTS is {points}")
35+
return True
36+
37+
38+
39+
def main():
40+
# First round of game
41+
if (flag == 0):
42+
first_drop()
43+
# if player can pass from first round now player should
44+
# drop dice until one of the condition is Come true
45+
while True:
46+
a = drop_dice()
47+
one , two = a
48+
# if player dice after first round come's 7 - player lose
49+
if (one + two == 7):
50+
print(f"Player Lose")
51+
sys.exit(1)
52+
# if player dice after first round becomes equal to points - player wins
53+
elif (one + two == points):
54+
print("Player win! Points and Dice are same")
55+
sys.exit(0)
56+
57+
58+
main()

0 commit comments

Comments
 (0)