Advertisement
Guest User

Untitled

a guest
Apr 4th, 2020
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.92 KB | None | 0 0
  1. N = int(input("Введите размер квадрата: "))
  2. import time, os
  3. pole = [[0 for _ in range(N)] for _ in range(N)]
  4. x = N // 2
  5. y = N // 2
  6. direction = [-1, 0]
  7. while x >= 0 and x < N and y >= 0 and y < N:
  8.     if pole[y][x] == 0:
  9.         pole[y][x] = 1
  10.         if direction[0] == -1:
  11.             direction = [0,-1]
  12.         elif direction[0] == 1:
  13.             direction = [0,1]
  14.         elif direction[1] == -1:
  15.             direction = [1,0]
  16.         else:
  17.             direction = [-1,0]
  18.         x += direction[0]
  19.         y += direction[1]
  20.     else:
  21.         pole[y][x] = 0
  22.         if direction[0] == -1:
  23.             direction = [0,1]
  24.         elif direction[0] == 1:
  25.             direction = [0,-1]
  26.         elif direction[1] == -1:
  27.             direction = [-1,0]
  28.         else:
  29.             direction = [1,0]
  30.         x += direction[0]
  31.         y += direction[1]
  32.     for yParse in range(N):
  33.         for xParse in range(N):
  34.             char = ''
  35.             if pole[yParse][xParse] == 0:
  36.                 char = 'O'
  37.             else:
  38.                 char = 'g'
  39.             print(char, end='')
  40.         print()
  41.     time.sleep(0.5)
  42.     os.system('cls')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement