-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathDice Rolling Game
52 lines (43 loc) · 1.37 KB
/
Dice Rolling Game
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
import random as r
def check_result(up,cp,name):
if(up == cp):
print("Tie! You and computer have same points")
elif(up > cp):
print(name," is a winner!")
elif(cp > up):
print("computer is a winner!")
while(True):
name = input("Enter your name: ")
rounds = int(input("How many rounds do you want to play?"))
terminated = 0
up,cp = 0,0
for i in range(rounds):
opt = int(input("Roll a dice by pressing 1(0 for quit): "))
ugn = 0
if(opt == 1):
ugn = r.randint(1,6)
print("You rolled a dice and got ",ugn)
elif(opt == 0):
print("Terminated..")
check_result(up, cp, name)
print(name ,": ",up," points\tComputer: ",cp," points","\n")
terminated = 1
break
cgn = r.randint(1, 6)
print("Computer rolled a dice and got ",cgn)
if(ugn > cgn):
up += 1
elif(ugn < cgn):
cp += 1
elif(ugn == cgn):
up += 1
cp += 1
print(name ,": ",up," points\tComputer: ",cp," points","\n")
if(terminated == 0):
check_result(up, cp, name)
print(name ,": ",up," points\tComputer: ",cp," points","\n")
check = int(input("Do you want to Play Again?(1 for yes/0 for no) "))
if(check == 1):
pass
elif(check == 0):
break