turtle画图

该篇文章分享了使用Python的turtle模块进行图形编程的两个实验,包括绘制彩色的圆形、三角形、正方形,并介绍了如何改变形状的边数以及填充颜色。此外,还提及了Python的基础输入输出功能,如print和input函数的使用。
摘要由CSDN通过智能技术生成

python学习一些小笔记与大家分享


前言

python的turtle画图功能,以几个实验为例,

另外还有几个输入输出相关知识

实验一:

# 学习利用 Turtle 模块编写程序
# 画出圆形、等边三角形、正方形,
# 并填充颜色。参考程序如下

import turtle

turtle.speed(1)

turtle.pensize(4)

turtle.pencolor("black")

turtle.penup()

turtle.goto(0, 0)

turtle.pendown()

turtle.circle(50)

turtle.penup()

turtle.goto(100, 0)

turtle.pendown()

turtle.begin_fill()

turtle.color("red")

turtle.circle(50, steps=3)

turtle.end_fill()

turtle.penup()

turtle.goto(100, 100)

turtle.pendown()

turtle.begin_fill()

turtle.color("black")

turtle.circle(50, steps=4)

turtle.end_fill()

turtle.penup()

turtle.goto(0, 100)

turtle.pendown()

turtle.begin_fill()

turtle.color("blue")

turtle.circle(50, steps=6)

turtle.end_fill()

turtle.done()

实验二

# (Turtle: draw shapes) Write a program that draws
# a triangle, square, pentagon, hexagon,
# and octagon, as shown in Figure.
# Note that the bottom edges of these
# shapes are parallel to the x-axis.
# (Hint: For a triangle with a bottom
# line parallel to the x-axis, set
# the turtle's heading to 60 degrees.)


import turtle

turtle.pensize(3)  # Set pen thickness to 3 pixels
turtle.speed(1)

turtle.penup()  # Pull the pen up
turtle.goto(-100, -50)
turtle.pendown()  # Pull the pen down
turtle.begin_fill()  # Begin to fill color in a shape
turtle.color("red")
turtle.circle(40, steps=3)  # Draw a circle
turtle.end_fill()  # Fill the shape
turtle.penup()
turtle.goto(0, -50)
turtle.pendown()
turtle.begin_fill()  # Begin to fill color in a shape
turtle.color("blue")
turtle.circle(40, steps=4)  # Draw a triangle
turtle.end_fill()  # Fill the shape
turtle.penup()
turtle.goto(100, -50)
turtle.pendown()
turtle.begin_fill()  # Begin to fill color in a shape
turtle.color("green")
turtle.circle(40, steps=5)  # Draw a square
turtle.end_fill()  # Fill the shape
turtle.penup()
turtle.goto(100, 50)
turtle.pendown()
turtle.begin_fill()  # Begin to fill color in a shape
turtle.color("blue")
turtle.circle(40, steps=6)  # Draw a square
turtle.end_fill()  # Fill the shape
turtle.penup()
turtle.goto(0, 50)
turtle.pendown()
turtle.begin_fill()  # Begin to fill color in a shape
turtle.color("black")
turtle.circle(40, steps=8)  # Draw a square
turtle.end_fill()  # Fill the shape
turtle.hideturtle()
turtle.done()

 补充内容(python的其他基础知识)

1,输出函数(print)

fomat方法介绍

print('{},{}'.format('1', '2'))

print('{:.2f}'.format(12))

运行结果

 2,输入函数(input)

调用方法input("可以在此处添加一些提示语句")

s = eval(input())

print(s)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

就那样啊啊啊啊啊

你的鼓励将是我创作的最大动力

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

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

打赏作者

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

抵扣说明:

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

余额充值