7.15课后作业

7.15作业

1.使用turtle库,绘制一个八边形。

import turtle as t
import random as r
t.hideturtle()
t.setup(600,600)
t.pensize(5)
t.colormode(255)
for i in range(8):
    t.color(r.randint(0,255),r.randint(0,255),r.randint(0,255))
    t.fd(50)
    t.right(45)
t.done()

2.使用turtle库,绘制一个八角图形。

import turtle as t
import random as r
t.hideturtle()
t.setup(600,600)
t.pensize(5)
t.colormode(255)
for i in range(8):
    t.color(r.randint(0,255),r.randint(0,255),r.randint(0,255))
    t.fd(200)
    t.right(135)
t.done()

3.简述import <模块名>/from <模块名> import */import <模块名> as <新模块名>三者的区别

import <模块名>:多个库之间不会冲突,每次调用该模块都必须键入库名,使用不方便,但不会有冲突。
from <模块名> import *:程序导入单个库时,不用依次键入库名,只用直接调用模块中的方法,但当有多个库同时导入时,会引起多个库调用的冲突,不建议使用。
import <模块名> as <新模块名>:不会引起冲突,可用新模块名代替模块名对模块中的方法进行调用,代码简洁,使用方便。

4.设计程序,要求:循环打印数列`1,3,5,...,99

for i in range(1,100):
    if i % 2 != 0:
        print(i)

5.使用turtle库,绘制一个自己喜欢的图形,并截图发到微信群中,别告诉我你喜欢一条直线(/哭笑)。

import turtle as t
import random

t.hideturtle()
t.setup(500,500)
t.pensize(3)

t.speed(0)
t.color("black","blue")
t.begin_fill()
t.circle(100)
t.end_fill()
t.color("black","white")
t.begin_fill()
t.circle(80)
t.end_fill()

t.penup()
t.left(90)
t.fd(100)
t.right(90)
t.pendown()

t.color("black","red")
t.begin_fill()
t.circle(10)
t.end_fill()

t.right(90)
t.fd(50)

t.right(90)
t.circle(-40,60)
t.circle(-40,-60)
t.right(180)
t.circle(40,60)
t.circle(40,-60)

t.up()
t.fd(55)
t.left(90)
t.fd(100)
t.down()

t.begin_fill()
t.color("black","white")
t.circle(20)
t.end_fill()

t.begin_fill()
t.color("black","black")
t.circle(10)
t.end_fill()

t.up()
t.fd(15)
t.left(90)
t.fd(102)
t.down()

t.begin_fill()
t.color("black","white")
t.circle(20)
t.end_fill()

t.circle(20,-45)
t.right(45)
t.bk(12)
t.right(90)
t.fd(5)
t.left(90)
t.begin_fill()
t.color("black","black")
t.circle(10)
t.end_fill()

t.up()
t.goto(0,0)
t.fd(80)
t.left(90)
t.fd(50)
t.down()
t.right(20)
t.fd(85)

t.up()
t.goto(0,0)
t.seth(90)
t.down()

t.up()
t.fd(70)
t.left(90)
t.fd(50)
t.down()
t.fd(85)

t.up()
t.goto(0,0)
t.seth(90)
t.down()

t.up()
t.fd(60)
t.left(90)
t.fd(50)
t.left(20)
t.down()
t.fd(85)

t.up()
t.goto(0,0)
t.seth(90)
t.down()

t.up()
t.fd(80)
t.right(90)
t.fd(50)
t.down()
t.left(20)
t.fd(85)

t.up()
t.goto(0,0)
t.seth(90)
t.down()

t.up()
t.fd(70)
t.right(90)
t.fd(50)
t.down()
t.fd(85)

t.up()
t.goto(0,0)
t.seth(90)
t.down()

t.up()
t.fd(60)
t.right(90)
t.fd(50)
t.right(20)
t.down()
t.fd(85)

t.up()
t.goto(0,0)
t.seth(0)
t.bk(70)
t.down()

for i in range(3):
    t.colormode(255)
    t.color(random.randint(0,255),random.randint(0,255),random.randint(0,255))
    t.fd(150)
    t.right(120)

t.up()
t.right(90)
t.fd(73)
t.down()
t.begin_fill()
t.color("black","blue")
t.circle(20)
t.end_fill()

t.up()
t.left(90)
t.fd(103)
t.right(90)
t.fd(10)
t.down()
t.begin_fill()
t.color("black","blue")
t.circle(20)
t.end_fill()

t.done()

转载于:https://www.cnblogs.com/dadazunzhe/p/11190763.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值