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

 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from math import *
from tkinter import *
root = Tk()
n =int(input())
t = 500//(2**n)
canv = Canvas(root, width = 1100, height = 1100, bg = 'white')
x,y = 500,500
def LL():
global x
xl = x
x -= t
canv.create_line(xl, y, x , y, width = 1)
def LR():
global x
xl = x
x += t
canv.create_line(xl , y, x , y, width = 1)
def LU():
global y
yl = y
y += t
canv.create_line(x , yl, x , y, width = 1)
def LD():
global y
yl = y
y -= t
canv.create_line(x , yl, x , y, width = 1)
def GA(k):
if k > 0:
GD(k-1)
LL()
GA(k-1)
LD()
GA(k-1)
LR()
GB(k-1)
def GB(k):
if k > 0:
GC(k-1)
LU()
GB(k-1)
LR()
GB(k-1)
LD()
GA(k-1)
def GC(k):
if k > 0:
GB(k-1)
LR()
GC(k-1)
LU()
GC(k-1)
LL()
GD(k-1)
def GD(k):
if k > 0:
GA(k-1)
LD()
GD(k-1)
LL()
GD(k-1)
LU()
GC(k-1)
f = int(input())
if f == 1:GA(n)
elif f == 2:GB(n)
elif f == 3:GC(n)
else:GD(n)
canv.pack()
root.mainloop()