-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdice_game.py
More file actions
55 lines (39 loc) · 1.24 KB
/
dice_game.py
File metadata and controls
55 lines (39 loc) · 1.24 KB
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
# Johnathan Wang
# Last edited: May 12, 2019
import random
points = 5
def value_check():
guess = int(input('Guess a number: '))
print('You guessed %d' % guess)
first_dice = random.randint(1, 3)
second_dice = random.randint(1, 3)
value = first_dice * second_dice
print('You rolled a %d and a %d, which has the product of %d' % (first_dice, second_dice, value))
global points
if guess == value:
print('Good guess! You get a point!')
points = points + 1
print('You now have %d points! \n' % points)
if points == 5:
print('Congratulations! You win the game!')
else:
value_check()
else:
while points == 0:
print('You have no more points to lose!')
print('Would you like to roll again?')
answer = input('Enter yes or no: \n')
if answer == "no":
print("Better luck next time!")
break
else:
points = 0
value_check()
else:
print('Bad guess! You lose a point!')
points = points - 1
print('You now have %d points \n' % points)
value_check()
def main():
value_check()
main()