Commit fe07bf1a authored by Godavarthi Gnaneshwar's avatar Godavarthi Gnaneshwar
Browse files

Snake and Ladder game

parent fd64864e
import random
#import numpy as np
snake={60:6,78:34,98:23,54:45}
ladders={14:43,24:67,38:83,49:97}
player1=0
player2=0
def check_for_snakes_and_ladders(n):
if n in ladders:
print("It's a ladder climb up")
n=ladders[n]
elif n in snake:
print("It's a snake come down")
n=snake[n]
return n
def roll_dice(r):
d=random.choice([1,2,3,4,5,6])
d=r+d
if(d<=100):
return d
else:
return r
while((player1<99) & (player2<99)):
print("it's player1 turn")
player1=roll_dice(player1)
player1=check_for_snakes_and_ladders(player1)
print("position of player1 is %d"% player1)
if player1==100:
print("player1 won")
break
print("it's player2 turn")
player2=roll_dice(player2)
player2=check_for_snakes_and_ladders(player2)
print("player2 is %d"% player2)
if player2==100:
print("player2 won ")
break
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment