[Python123]Python语言程序设计:练习2-Python基本图形绘制 (第2周) 1-5题

一、Python蟒蛇绘制解析:

#PythonDraw.py
import turtle
turtle.setup(1920, 1080, 0, 0)   #setup设置窗体大小及位置(宽, 高, 左上角点x, 左上角点y)
turtle.penup()          #抬起画笔(海龟)
turtle.fd(-250)         #海龟倒退250个像素
turtle.pendown()        #放下画笔(海龟)
turtle.pensize(25)      
turtle.pencolor("purple")   #画笔颜色
turtle.seth(-40)        #海龟方向为-40度方向(直角坐标内)
for i in range(4):      #for下的语句循环4次
    turtle.circle(40, 80)      #海龟走曲线(半径,弧度)
    turtle.circle(-40, 80)     
turtle.circle(40, 80/2)        #绘制小半个弧形
turtle.fd(40)               #向海龟方向前进40像素,构成蟒蛇脖子
turtle.circle(16, 180)       
turtle.fd(40 * 2/3)          #半圆形和直线构成蟒蛇头部   
turtle.done()               #绘制完毕后程序需手动退出

 

二、

turtle正方形绘制

turtle六边形绘制

turtle叠边形绘制

turtle同切圆绘制

#SquareDraw.py      turtle正方形绘制
import turtle 

turtle.setup(800,800,200,100)
turtle.penup()
turtle.goto(-200,-200)
turtle.pendown()
turtle.pensize(10)
for i in range(4):
    turtle.fd(400)
    turtle.left(90)
turtle.done()


#HexagonDraw.py        turtle六边形绘制
import turtle 

turtle.setup(800,800,200,100)
turtle.penup()
turtle.goto(-100,-200)
turtle.pendown()
turtle.pensize(10)
for i in range(6):
    turtle.fd(200)
    turtle.left(60)
turtle.done()


#EdgeshapeDraw.py            turtle叠边形绘制
import turtle 

turtle.setup(800,800,200,100)
turtle.penup()
turtle.goto(-100,-200)
turtle.pendown()
turtle.pensize(10)
for i in range(9):
    turtle.fd(200)
    turtle.left(80)
turtle.done()


#TagentCirclesDraw          turtle同切圆绘制
import turtle 

turtle.setup(800,800,200,100)
turtle.pensize(5)
turtle.circle(50, 360)
turtle.circle(70, 360)
turtle.circle(90, 360)
turtle.circle(110, 360)

turtle.done()   

 

 三、长度转换 I

#Convert_Inch_Meter
LenthStr = input()
if LenthStr[-1] in ['M', 'm']:
    Inch = eval(LenthStr[0:-1]) * 39.37
    print('{:.3f}in'.format(Inch))
else:
    Meter = eval(LenthStr[0:-2]) / 39.37
    print("{:.3f}m".format(Meter))

 

你可能感兴趣的:([Python123]Python语言程序设计:练习2-Python基本图形绘制 (第2周) 1-5题)