Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
32
Task/Nim-game/Python/nim-game.py
Normal file
32
Task/Nim-game/Python/nim-game.py
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
print("Py Nim\n")
|
||||
|
||||
def getTokens(curTokens):
|
||||
global tokens
|
||||
|
||||
print("How many tokens would you like to take? ", end='')
|
||||
take = int(input())
|
||||
|
||||
if (take < 1 or take > 3):
|
||||
print("Number must be between 1 and 3.\n")
|
||||
getTokens(curTokens)
|
||||
return
|
||||
|
||||
tokens = curTokens - take
|
||||
print(f'You take {take} tokens.')
|
||||
print(f'{tokens} tokens remaining.\n')
|
||||
|
||||
def compTurn(curTokens):
|
||||
global tokens
|
||||
|
||||
take = curTokens % 4
|
||||
tokens = curTokens - take
|
||||
print (f'Computer takes {take} tokens.')
|
||||
print (f'{tokens} tokens remaining.\n')
|
||||
|
||||
|
||||
tokens = 12
|
||||
while (tokens > 0):
|
||||
getTokens(tokens)
|
||||
compTurn(tokens)
|
||||
|
||||
print("Computer wins!")
|
||||
Loading…
Add table
Add a link
Reference in a new issue