-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathdice.py
89 lines (77 loc) · 1.83 KB
/
dice.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# This code is made by MRayan Asim
import random
import time
print("hello this dice rolling game is made by MRayan Asim hope you will like this!😊")
time.sleep(3)
def roll_dice():
dice_faces = [
# Dice face 1
"""
----------
| |
| O |
| |
----------
""",
# Dice face 2
"""
----------
| O |
| |
| O |
----------
""",
# Dice face 3
"""
----------
| O |
| O |
| O |
----------
""",
# Dice face 4
"""
----------
| O O |
| |
| O O |
----------
""",
# Dice face 5
"""
----------
| O O |
| O |
| O O |
----------
""",
# Dice face 6
"""
----------
| O O O |
| |
| O O O |
----------
""",
]
min_value = 1
max_value = 6
score = 0
roll_again = True
while roll_again:
user_guess = int(input("Guess the number for dice (1-6): "))
print("Rolling the dice...")
time.sleep(1) # Pause for 1 second to create rolling effect
dice_value = random.randint(min_value, max_value)
print(dice_faces[dice_value - 1]) # Display the corresponding dice face
if user_guess == dice_value:
print("Congratulations! You guessed it right.")
score += 1
else:
print("Sorry, wrong guess.")
print("Score:", score)
roll_again_input = input("Roll the dice again? (y/n): ")
roll_again = roll_again_input.lower() == "y"
print("Final score:", score)
print("Thank you for playing!")
roll_dice()