Python MOOC练习2

版权声明:本文为博主原创文章,转载请务必注明出处和作者,谢谢合作! https://blog.csdn.net/zhanshen112/article/details/81634544

1、turtle正方形绘制

import turtle
turtle.fd(20)
turtle.seth(90)
turtle.fd(20)
turtle.seth(180)
turtle.fd(20)
turtle.seth(270)
turtle.fd(20)

2、长度转换 I

length=input()
if length[-1] in ["m"]: #m2in
    inlengh=eval(length[0:-1])*39.37
    print("{:.3f}in".format(inlengh))
elif length[-1] in ["n"]: #in2m
    inlengh=eval(length[0:-2])/39.37
    print("{:.3f}m".format(inlengh))
else:
    print("输入有误")

3、正方形螺旋线

from turtle import *
for i in range(60):
    pencolor(i*2.5/100,i*1/100,i*0.01)
    fd(i*6)
    left(90)

4、同心圆函数

'''
Name: concentric circles function
function:draw a series of  concentric circles
usage:target(innerR,gap,pencolor,number)
'''
from turtle import *
def target(innerR,gap,number):
    for i in range(number):
        circle(innerR+i*gap)
        penup()
        goto(0,-gap*(i+1))
        pendown()
    

猜你喜欢

转载自blog.csdn.net/zhanshen112/article/details/81634544
今日推荐