Python100例 我的实现展示(56-60例)

Python100例 我的实现展示(56-60例)

from tkinter import *
import turtle

'''56、画图,学用circle画圆形。'''


def test_exam_56():
    x1, y1 = 100, 100
    x2, y2 = 100, -100
    x3, y3 = -100, -100
    x4, y4 = -100, 100

    # 绘制折线
    turtle.penup()
    turtle.goto(x1, y1)
    turtle.pendown()
    turtle.circle(10)
    turtle.goto(x2, y2)
    turtle.circle(20)
    turtle.goto(x3, y3)
    turtle.circle(30)
    turtle.goto(x4, y4)
    turtle.circle(50)
    turtle.done()


'''57、画图,学用line画直线。'''


def test_exam_57():
    x1, y1 = 100, 100
    x2, y2 = 100, -100
    x3, y3 = -100, -100
    x4, y4 = -100, 100

    # 绘制折线
    turtle.penup()
    turtle.goto(x1, y1)
    turtle.pendown()

    turtle.goto(x2, y2)
    turtle.goto(x3, y3)
    turtle.goto(x4, y4)
    turtle.done()


'''58、画图,学用rectangle画方形。(这题不会,模仿学习的代码)'''


def test_exam_58():
    tk = Tk()
    tk.title('rectangle')
    canvas = Canvas(tk, width=400, height=400, bg='red')
    x0 = 263
    y0 = 263
    x1 = 275
    y1 = 275
    for i in range(19):
        canvas.create_rectangle(x0, y0, x1, y1)
        x0 -= 5
        y0 -= 5
        x1 += 5
        y1 += 5
    canvas.pack()
    tk.mainloop()


'''59、画图,综合例子。(程序分析:利用for循环控制100-999个数,每个数分解出个位,十位,百位。)'''


def test_exam_59():
    canvas = Canvas(width=300, height=300, bg='green')
    canvas.pack(expand=YES, fill=BOTH)
    x0 = 150
    y0 = 100
    canvas.create_oval(x0 - 10, y0 - 10, x0 + 10, y0 + 10)
    canvas.create_oval(x0 - 20, y0 - 20, x0 + 20, y0 + 20)
    canvas.create_oval(x0 - 50, y0 - 50, x0 + 50, y0 + 50)
    b = 0.809
    for i in range(16):
        a = 2 * math.pi / 16 * i
        x = math.ceil(x0 + 48 * math.cos(a))
        y = math.ceil(y0 + 48 * math.sin(a) * b)
        canvas.create_line(x0, y0, x, y, fill='red')
    canvas.create_oval(x0 - 60, y0 - 60, x0 + 60, y0 + 60)

    for k in range(501):
        for i in range(17):
            a = 2 * math.pi / 16 * i + (2 * math.pi / 180) * k
            x = math.ceil(x0 + 48 * math.cos(a))
            y = math.ceil(y0 + 48 * math.sin(a) * b)
            canvas.create_line(x0, y0, x, y, fill='red')
        for j in range(17):
            a = 2 * math.pi / 16 * j + (2 * math.pi / 180) * k
            x = math.ceil(x0 + 48 * math.cos(a))
            y = math.ceil(y0 + 48 * math.sin(a) * b)
            canvas.create_line(x0, y0, x, y, fill='red')
    mainloop()


'''60、计算字符串长度。'''


def test_exam_60():
    s = input("请输入一行字符串,程序将计算并输出该字符串的长度\n")
    print("输入字符串的长度为:{0}".format(len(s)))

if __name__ == '__main__':

    # test_exam_56()
    # test_exam_57()
    # test_exam_58()
    # test_exam_59()
    test_exam_60()

test_exam_56跑出来的结果如下图:
在这里插入图片描述
test_exam_57跑出来的结果如下图:
在这里插入图片描述

test_exam_58跑出来的结果如下图:
在这里插入图片描述

test_exam_59跑出来的结果如下图:
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

阿尔卑斯的畅想

欢迎打赏,一起每天进步一点点!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值