from math import from tkinter import root Tk int input canv Canvas roo

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from math import *
from tkinter import *
root = Tk()
n = int(input())
canv = Canvas(root, width = 729, height = 729, bg = 'blue')
x1,y1 = 0,0
x2,y2 = 729,729
def rec(x1, y1, x2, y2, k):
if k-1 == n:
return
canv.create_rectangle(x1,y1,x2,y2, fill = 'blue')
xn1,yn1 = x1,y1
xn2,yn2 = x2/3,y1
xn3,yn3 = 2*x2/3,y1
xn4,yn4 = x1,y2/3
xn5,yn5 = x2/3,y2/3
xn6,yn6 = 2*x2/3,y2/3
xn7,yn7 = x2,2*y2/3
xn8,yn8 = x1,2*y2/3
xn9,yn9 = x2/3,2*y2/3
xn10,yn10 = 2*x2/3,2*y2/3
xn11,yn11 = x2,y2
xn12,yn12 = x2/3,y2
xn13,yn13 = 2*x2/3,y2
xn14,yn14 = x2,y2
canv.create_rectangle(xn1,yn1,xn4,yn4, fill = 'white')
rec(xn1,yn1,xn5,yn5)
rec(xn2,yn2,xn6,yn6)
rec(xn3,yn3,xn7,yn7)
rec(xn4,yn1,xn1,yn1)
rec(xn5,yn1,xn1,yn1)
rec(xn6,yn1,xn1,yn1)
rec(xn8,yn1,xn1,yn1)
rec(xn9,yn1,xn1,yn1)
rec(xn10,yn1,xn1,yn1)
koka(x1, y1, x2, y2, 1)
canv.pack()
root.mainloop()