Advertisement
Guest User

Untitled

a guest
Apr 7th, 2020
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.10 KB | None | 0 0
  1. import random
  2.  
  3. def whoIsFirst():
  4.     if random.randint == 0:
  5.         return 'Игрок 1'
  6.     else:
  7.         return 'Игрок 2'
  8.  
  9. def makeMove():
  10.     move = ' '
  11.     while move not in '1 2 3'.split():
  12.         print('Сколько палочек вы хотите взять? (не больше 3)')
  13.         move = input()
  14.     return int(move)
  15.  
  16. def drawBoard(theTurn, theSticks):
  17.     print('Осталось палочек: %s' %(theSticks))
  18.     print('Ходит %s' %(theTurn))
  19.  
  20. sticks = 10
  21.  
  22. turn = whoIsFirst()
  23. print('Первым ходит %s' %(turn))
  24. while sticks > 0:
  25.     if turn == 'Игрок 1':
  26.         drawBoard(turn, sticks)
  27.         move = makeMove()
  28.         sticks -= move
  29.         if sticks <= 0:
  30.             print('Победил %s!' %(turn))
  31.             break
  32.         turn = 'Игрок 2'
  33.     else:
  34.         turn = 'Игрок 2'
  35.     if turn == 'Игрок 2':
  36.         drawBoard(turn, sticks)
  37.         move = makeMove()
  38.         sticks -= move
  39.         if sticks <= 0:
  40.             print('Победил %s!' %(turn))
  41.             break
  42.         turn = 'Игрок 1'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement