Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- oristone = 100
- def repeat():
- game()
- def checkint(varname):
- try:
- int(varname)
- return True
- except ValueError:
- return False
- def playerinput(player):
- print '--------------------\nPlayer'+ str(player) + 'turn\n--------------------'
- stonetotake=raw_input('How many stone would you like to take ? : ')
- while checkint(stonetotake) == False :
- stonetotake = raw_input('Pls input a valid number : ')
- else:
- while int(stonetotake) <1 or int(stonetotake) >5 or int(stonetotake) > stone:
- stonetotake = raw_input('Pls input a valid number : ')
- while checkint(stonetotake) == False :
- stonetotake = raw_input('Pls input a valid number : ')
- else:
- pass
- global tempstone
- tempstone=int(stonetotake)
- return int(stonetotake)
- def game():
- global stone
- stone=oristone
- raw_input('Hit enter to start the game ')
- print '\nStone pile : '+str(stone)
- while stone >0 :
- if stone - playerinput(1) >0:
- stone = stone - tempstone
- print 'Stone pile : '+str(stone)
- if stone - playerinput(2) >0:
- stone = stone - tempstone
- print 'Stone pile : '+str(stone)
- elif stone - tempstone == 0:
- print 'Player 2 wins!'
- stone = stone - tempstone
- elif stone - tempstone == 0:
- print 'Player 1 wins!'
- stone = stone - tempstone
- else:
- ans=raw_input("Do you want to play again? insert 'Y' if YES or press ENTER if NO : ")
- if ans == 'Y' :
- repeat()
- repeat()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement