#Nim program prototype #variables for the game. sticks = int(13) playerState = int(0) #game mechanics while (sticks > 0): if (playerState %2 != 1): playerMove = int(raw_input("Player One, please enter your move:")) if (playerMove > 0) and (playerMove < 5) and (playerMove <= sticks): sticks = sticks - playerMove playerState +=1 print sticks print playerState else: print "Illegal move. Try again." else: playerMove = int(raw_input("Player Two, please enter your move:")) if (playerMove > 0) and (playerMove < 5) and (playerMove <= sticks): sticks = sticks - playerMove playerState +=1 print sticks print playerState winner = int(playerState % 2) if (winner != 1): print "Congratulations player 1" else: print "Congratulations player 2"
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question