首页 > 其他分享 >实验6

实验6

时间:2023-06-07 13:11:41浏览次数:30  
标签:moveto 源代码 range 实验 import main def

实验任务1

task1

源代码:

from turtle import *
def move(x, y):
    penup()
    goto(x, y)
    pendown()
def draw(n, size = 100):
    for i in range(n):
        fd(size)
        left(360/n)
def main():
    pensize(2)
    pencolor('red')
    move(-200, 0)
    draw(3)
    move(0, 0)
    draw(4)
    move(200, 0)
    draw(5)
    hideturtle()
    done()
main()

实验结果:

 

task2

源代码:

from turtle import *
def moveto(x, y):
    penup()
    goto(x, y)
    pendown()
def main():
    pensize(2)
    pencolor('blue')
    moveto(-150, 0)
    circle(50)
    moveto(0, 0)
    circle(50, steps = 4)
    moveto(150, 0)
    circle(50, steps = 5)
    moveto(300, 0)
    circle(50, steps = 6)
    hideturtle()
    done()
main()

实验结果:

 

实验任务2

task1

源代码;

from turtle import *
def moveto(x, y):
    penup()
    goto(x, y)
    pendown()
def main():
    setup(800, 600)
    radius = 20
    offset = 20
    for i in range(9):
        moveto(0, -radius)
        circle(radius)
        radius += offset
    hideturtle()
    done()
main()

实验结果:

 

task2

源代码:

from turtle import *
from random import random
def moveto(x, y):
    penup()
    goto(x, y)
    pendown()
def gen_color():
    return tuple((random() for i in range(3)))
def main():
    setup(800, 600)
    radius = 180
    offset = 20
    for i in range(8):
        moveto(0, -radius)
        color(gen_color())
        begin_fill()
        circle(radius)
        end_fill()
        radius -= offset
    hideturtle()
    done()
main()

实验代码:

 

实验任务3

task1

源代码:

from turtle import *
def square(size = 50, rgb = 'orange'):
    pencolor(rgb)
    for i in range(4):
        fd(size)
        left(90)
def main():
    setup(800, 600)
    speed(0)
    n = 10
    for i in range(n):
        square(80)
        left(360/n)
    hideturtle()
    done()
main()

实验结果:

task2

源代码:

from turtle import *
setup(800, 600)
pencolor('pink')
n = 10
for i in range(10):
    for j in range(2):
        circle(80, 90)
        left(90)
    right(360/n)
hideturtle()
done()

实验结果:

 

 

实验任务4

源代码:

from turtle import *
setup(800, 600)
bgcolor('black')
pencolor('white')
speed(0)
angle = 0
size = 2
n = 5
count = 50
for i in range(count):
    fd(size)
    angle += 360/n
    seth(angle)
    size += 5
hideturtle()
done()

实验结果:

 

实验任务5

task1

源代码:

from turtle import *
def start(x,y):
    penup()
    goto(x,y)
    pendown()
def main(c,n,l):
    color(c)
    begin_fill()
    for i in range(n):
        fd(l)
        left(360/n)
    end_fill()
start(-100,-100)
main('black',4,200)
start(-100,0)
right(45)
main('red',4,100*2**(1/2))
hideturtle()
done()

实验结果:

task2

源代码:

from turtle import *
color('blue')
r = 20
for i in range(5):
    r += 20
    forward(r)
    left(90)
    circle(r,90)
    left(90)
    forward(r)
    left(90)
    forward(40)
    goto(0,0)
hideturtle()
done()

实验结果:

 

实验任务6

源代码:

from turtle import *
def moveto(x,y):
    penup()
    goto(x,y)
    pendown()
bgcolor('black')
moveto(200,-200)
color('yellow')
begin_fill()
left(135)
fd(200)
right(90)
fd(200)
left(90)
circle(200,270)
end_fill()
moveto(80,70)
dot(40,'black')
moveto(72,76)
dot(10,'white')
hideturtle()
done()

实验结果:

 

over!

 

标签:moveto,源代码,range,实验,import,main,def
From: https://www.cnblogs.com/khyyyds/p/17463031.html

相关文章

  • 实验五 文件应用编程
    task6withopen('data6.csv','r',encoding='gbk')asf:data=f.readlines()data.remove('原始数据\n')data0=[]foriindata:ifi[-1]=='\n':i=i[:-1]data0.append(float(i))print('原始......
  • 实验7 面向对象编程与内置模块
    task1classAccount:def__init__(self,name,account_number,initial_amount=10):self._name=nameself._card_no=account_numberself._balance=initial_amountdefdeposit(self,account):self._balance+=accountdefwit......
  • 实验5
    task6源代码:importcsvtitle=['原始数据','四舍五入后的数据']lst=[]yuan_lst=[]hou_lst=[]withopen('data6.csv','r')asf:read_lst=f.readlines()foriinrange(1,len(read_lst)):y=float(read_l......
  • 实验7 面向对象编程与内置模块
    实验任务1task1.py1classAccount:23def__init__(self,name,account_number,initial_amount=10):4self._name=name5self._card_no=account_number6self._balance=initial_amount7defdeposit(self,amount):......
  • 实验五 文件应用编程
    task6实验源码1importcsv23title=['原始数据','四舍五入后的数据']45lst=[]6yuan_lst=[]7hou_lst=[]8withopen('data6.csv','r')asf:9read_lst=f.readlines()10foriinrange(1,len(read_l......
  • 实验5
    task61importcsv2title=[]3info=[]45withopen('data6.csv','r',encoding='gbk')asf:6f_reader=csv.reader(f)7forlineinf_reader:8info.append(line)9x=info.pop(0)10title.appe......
  • 实验五
    任务6:withopen('data6.csv','r',encoding='gbk')asf:data=list(f.readlines())data=[i.strip('\n')foriindata]importdecimaldecimal.getcontext().rounding='ROUND_HALF_UP'title=[data[0......
  • 实验5
    实验源码:withopen('data6.csv','r',encoding='gbk')asf:data=list(f.readlines())data=[i.strip('\n')foriindata]importdecimaldecimal.getcontext().rounding='ROUND_HALF_UP'title=[data[......
  • 实验7 面向对象编程与内置模块
    一、实验结论:1.实验任务1:task1.py程序源码:1'''2银行账户3数据:持卡人姓名、账号、当前余额4操作:取款、存款、打印账户信息、返回账户余额5'''67classAccount:8'''一个模拟银行账户的简单类'''910def__init__(self,name,account_nu......
  • 实验五
    实验任务6task6.py1withopen('data6.csv','r',encoding='gbk')asf:2old_data=f.read().split('\n')3delold_data[0]4processed_data=[]5foriinrange(len(old_data)):6ifeval(old_data[i])......