import random
import turtle
def xian(a, b):
turtle.goto(0, 0)
turtle.goto(a, 0)
turtle.goto(b, 0)
turtle.goto(0, 0)
def draw():
draw_number = turtle.textinput("输入重复次数", "重复次数?")
draw_number = int(draw_number)
draw_number2 = turtle.textinput("输入宽度", "宽度?")
draw_number2 = int(draw_number2)
a1 = draw_number * 100 / 2
a1 = int(a1)
a2 = draw_number * 100 / 2
b2 = draw_number * 100 / 2 - a2 - a2
turtle.screensize(1600, a1)
bc1 = draw_number2 * 100 / 2
bc2 = draw_number2 * 100 / 2 - bc1 - bc1
random.randint(bc2, bc1)
random.randint(b2, a2)
draw_number = draw_number + 1
b = draw_number
xian(bc1, bc2)
turtle.hideturtle()
turtle.speed(0)
turtle.penup()
turtle.goto(-125, a1)
turtle.pendown()
turtle.write('K最临近算法表格', font=("Arial", 15, "normal"))
turtle.penup()
c = 1
a3 = a1 + 100
for u in range(draw_number):
yi = a3 - 100
a3 = yi
if c >= 1:
if c < draw_number:
turtle.penup()
turtle.goto(bc2, yi)
turtle.backward(30)
b = b - 1
turtle.write(b, font=("Arial", 15, "normal"))
turtle.goto(bc2, yi)
turtle.pendown()
for i in range(draw_number2):
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
c = c + 1
else:
turtle.penup()
turtle.goto(bc2, yi)
turtle.backward(30)
b = b - 1
turtle.write(b, font=("Arial", 15, "normal"))
turtle.goto(bc2, yi)
for o in range(draw_number2):
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
c = c + 1
else:
b = b - 1
turtle.penup()
turtle.goto(bc2, yi)
turtle.pendown()
for _ in range(draw_number2):
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
c = c + 1
turtle.penup()
turtle.right(90)
turtle.forward(bc1 / 10)
turtle.left(90)
turtle.backward(bc1)
turtle.backward(bc1)
b = 0
for o in range(draw_number2 + 1):
turtle.penup()
turtle.write(b, font=("Arial", 15, "normal"))
b = b + 1
turtle.forward(100)
draw_number3 = turtle.textinput("输入重复次数", "重复次数?")
draw_number3 = int(draw_number3)
turtle.speed(0)
turtle.showturtle()
for e in range(draw_number3 * 10):
sd = draw_number3 * 50 - draw_number3 * 100
sd = int(sd)
ad = draw_number3 * 100 / 2
ad = int(ad)
ran_dom = random.randint(sd, ad)
ram_dom = random.randint(bc2, bc1)
m = ram_dom
n = ran_dom
print(m, n)
turtle.goto(m, n)
turtle.clone()
turtle.hideturtle()
draw()
turtle.done()
询问画表格
最新推荐文章于 2024-09-11 22:48:33 发布