-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdigui.py
84 lines (84 loc) · 1.73 KB
/
digui.py
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
73
74
75
76
77
78
79
80
81
82
83
84
# # 递归
# def fact(n):
# if n == 0:
# return 1
# return n*fact(n-1)
#
# print(fact(5))
#
# # 字符串反转
# # s = 'abcdefghijk'
# # print(s[::-1])
# def rvs(s):
# if s == '':
# return s
# else:
# return rvs(s[1:]) + s[0]
#
# # 斐波那契数列
# def fib(n):
# if n == 0 or n == 1:
# return 1
# else:
# return fib(n-1) + fib(n-2)
#
# # 汉诺塔问题
# count = 0
#
# def hanoi(n,src,dst,mid):
# global count
# if n == 1:
# print("{}:{}->{}".format(1,src,dst))
# count += 1
# else:
# hanoi(n-1,src,mid,dst)
# print("{}:{}->{}".format(n,src, dst))
# count += 1
# hanoi(n-1,mid,dst,src)
#
# hanoi(10,"A","C","B")
# print(count)
#
# # 科赫曲线
# #KochDrawV1.py
# import turtle
# def koch(size, n):
# if n == 0:
# turtle.fd(size)
# else:
# for angle in [0, 60, -120, 60]:
# turtle.left(angle)
# koch(size/3, n-1)
# def main():
# turtle.setup(800,400)
# turtle.penup()
# turtle.goto(-300, -50)
# turtle.pendown()
# turtle.pensize(2)
# koch(600,3) # 0阶科赫曲线长度,阶数
# turtle.hideturtle()
# main()
#
# #KochDrawV2.py
# import turtle
# def koch(size, n):
# if n == 0:
# turtle.fd(size)
# else:
# for angle in [0, 60, -120, 60]:
# turtle.left(angle)
# koch(size/3, n-1)
# def main():
# turtle.setup(600,600)
# turtle.penup()
# turtle.goto(-200, 100)
# turtle.pendown()
# turtle.pensize(2)
# level = 3 # 3阶科赫雪花,阶数
# koch(400,level)
# turtle.right(120)
# koch(400,level)
# turtle.right(120)
# koch(400,level)
# turtle.hideturtle()
# main()