Skip to content

Instantly share code, notes, and snippets.

@LandonPowell
Last active March 17, 2016 02:18
Show Gist options
  • Save LandonPowell/3a4432c7284f49a600d6 to your computer and use it in GitHub Desktop.
Save LandonPowell/3a4432c7284f49a600d6 to your computer and use it in GitHub Desktop.
Python Nim Implementation.
print(
"Welcome to Nim!:\n"+
"A simple game, where you're allowed to take "+
"one, two, or three marbles from a pile of 12.\n"+
"You compete against the computer to take the "+
"last marble.")
marbles = 12
def computerTake(amount):
global marbles # Python goes full retard without this.
print("I'll take "+ str(amount) +" of the marbles.")
marbles -= amount
print("Now we have "+ str(marbles) +" marbles left.")
while marbles:
print("\nMarbles: " + "o"*marbles)
choice = int(input("1, 2, or 3?> "))
marbles -= choice
if choice in range(1, 4): computerTake(4 - choice)
else: print("Stop cheating, sux0r!")
print("It looks like I win again!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment