作为一个Python初学者,我想通过写博客的方式来记录下来自己成长的过程,同时也分享一下自己学习到的知识。以下都是一个Python初学者对Python语言的一些浅见和个人理解。
基本操作 import turtle #导入turtle模块 turtle.width(10) #改变画笔宽度 turtle.showturtle() #显示箭头 turtle.write(“hahaha”) #写字符串 turtle.forward(300) #前进300像素 turtle.color(“red”) #画笔颜色改为red turtle.left(90) #箭头左转90度 turtle.forward(300) turtle.goto(0,50) #去坐标(0,50) turtle.goto(0,0) turtle.penup() #抬笔 turtle.goto(0,300) turtle.pendown() #下笔 turtle.circle(100) #画圆
练习1 #绘制奥运五环
import turtle
turtle.width(10)
turtle.color(“blue”) turtle.circle(50)
turtle.penup() turtle.goto(110,0) turtle.pendown() turtle.color(“black”) turtle.circle(50)
turtle.penup() turtle.goto(220,0) turtle.pendown() turtle.color(“red”) turtle.circle(50)
turtle.penup() turtle.goto(55,-60) turtle.pendown() turtle.color(“yellow”) turtle.circle(50)
turtle.penup() turtle.goto(165,-60) turtle.pendown() turtle.color(“green”) turtle.circle(50)
练习2 #定义多点坐标,绘制折线,并计算起始点和终点距离 import turtle import math #定义多点坐标 x1,y1 = 100,100 x2,y2 = 80,80 x3,y3 = 100,-100 x4,y4 = 80,-80 x5,y5 = -100,-100 x6,y6 = -80,-80 x7,y7 = -100,100 x8,y8 = -80,80
#绘制折线 turtle.penup() turtle.goto(x1,y1) turtle.pendown() turtle.goto(x2,y2) turtle.goto(x3,y3) turtle.goto(x4,y4) turtle.goto(x5,y5) turtle.goto(x6,y6) turtle.goto(x7,y7) turtle.goto(x8,y8)
#计算距离 distance = int(math.sqrt((x1-x4)**2 + (y1-y4)**2)) turtle.color(“red”) turtle.write(distance)
|