forked from aman-raza/Friends_Hack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Snake&Ladders.py
88 lines (74 loc) · 1.94 KB
/
Snake&Ladders.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
import random
lad={1:38,4:14,8:30,21:42,28:76,50:67,71:92,80:99}
snk={97:78,95:56,88:24,62:18,48:26,44:3,34:6,32:10}
def play():
p1=0
p2=0
print("Hey!! Lets play a game of Snakes and Ladders today.")
print("The ladders are as follows:")
print(lad)
print()
print("The Snakes are as follows:")
print(snk)
print()
print("To roll the die press 1 and to quit press 0")
p1n=input("Enter ypur name Player1: ")
p2n=input("Enter ypur name Player2: ")
while(p1n!=100 and p2n!=100):
print(p1n," roll the die")
ip1=int(input())
if ip1==1:
d=random.randint(1,6)
print(p1n,"You got a ",d)
p1=p1+d
print("Your now at",p1)
p1=ladder(p1)
p1=snake(p1)
else:
break
print(p2n," roll the die")
ip2=int(input())
if ip2==1:
d=random.randint(1,6)
print(p2n,"You got a ",d)
p2=p2+d
print("Your now at",p2)
p2=ladder(p2)
p2=snake(p2)
else :
break
print(p1n,"=",p1,"and",p2n,"=",p2)
print(d)
if(p1n==100 or p2n==100):
break
if(p1==100):
print("Hurray",p1n," you won")
if(p2==100):
print("Hurray",p2n," you won")
def ladder(p):
f=0
for i in lad:
if i==p:
p=lad[i]
f=1
break
else:
continue
if f==1:
print("Ladder")
print("Your final position is ",p)
return p
def snake(p):
k=0
for i in snk:
if i==p:
p=snk[i]
k=1
break
else:
continue
if k==1:
print("Snake")
print("Your final position is ",p)
return p
play()