首页 > 其他分享 >实验六

实验六

时间:2023-06-12 14:13:14浏览次数:31  
标签:10 20 range 源码 实验 import def

实验任务1

task1.1

实验源码

 1 from turtle import *
 2 def move(x, y):
 3     penup()
 4     goto(x, y)
 5     pendown()
 6 def draw(n, size = 100):
 7     for i in range(n):
 8         fd(size)
 9         left(360/n)
10 def main():
11     pensize(2)
12     pencolor('red')
13     move(-200, 0)
14     draw(3)
15     move(0, 0)
16     draw(4)
17     move(200, 0)
18     draw(5)
19     hideturtle()
20     done()
21 main()

运行测试截图

 

task1.2

实验源码

 1 from turtle import *
 2 def moveto(x, y):
 3     penup()
 4     goto(x, y)
 5     pendown()
 6 def main():
 7     pensize(2)
 8     pencolor('blue')
 9     moveto(-150, 0)
10     circle(50)
11     moveto(0, 0)
12     circle(50, steps = 4)
13     moveto(150, 0)
14     circle(50, steps = 5)
15     moveto(300, 0)
16     circle(50, steps = 6)
17     hideturtle()
18     done()
19 main()

运行测试截图

实验任务2

task2

实验源码

 1 from turtle import *
 2 def moveto(x, y):
 3     penup()
 4     goto(x, y)
 5     pendown()
 6 def main():
 7     setup(800, 600)
 8     radius = 20 # 圆初始半径
 9     offset = 20 # 同心圆每次位移量
10     for i in range(9):
11         moveto(0, -radius)
12         circle(radius)
13         radius += offset
14     hideturtle()
15     done()
16 main()

运行测试截图

task2.2

实验源码

 1 from turtle import *
 2 from random import random
 3 def moveto(x, y):
 4     penup()
 5     goto(x, y)
 6     pendown()
 7 
 8 def gen_color():
 9     return tuple((random() for i in range(3)))
10 def main():
11     setup(800,600)
12     radius = 20 # 圆初始半径
13     offset = 20 # 同心圆每次位移量
14     for i in range(9):
15         moveto(0, -radius)
16         color(gen_color())
17         circle(radius)
18         radius += offset
19     hideturtle()
20     done()
21 main()

运行测试截图

 

实验任务3

task3.1

实验源码

 1 from turtle import *
 2 def square(size = 50, rgb = 'pink'):
 3 
 4     pencolor(rgb)
 5     for i in range(4):
 6         fd(size)
 7         left(90)
 8 def main():
 9     setup(800, 600)
10     speed(0)
11     n = 10
12     for i in range(n):
13         square(80)
14         left(360/n)
15     hideturtle()
16     done()
17 main()

运行测试截图

task3.2

实验源码

 1 from turtle import *
 2 setup(800, 600)
 3 pencolor('pink')
 4 n = 10
 5 for i in range(10):
 6     # 绘制一片花瓣
 7     for j in range(2):
 8         circle(80, 90)
 9         left(90)
10     right(360/n)
11 hideturtle()
12 done()

运行测试截图

实验任务4

task4

实验源码

 1 from turtle import *
 2 setup(800, 600)
 3 bgcolor('black')
 4 pencolor('white')
 5 speed(0)
 6 angle = 0
 7 size = 2
 8 n = 5 # 螺旋n边形
 9 count = 50 # 循环次数
10 for i in range(count):
11     fd(size)
12     angle += 360/n
13     seth(angle)
14     size += 5
15 hideturtle()
16 done()

运行测试截图

实验任务5

task5.1

实验源码

 1 from turtle import *
 2 
 3 right(45)
 4 penup()
 5 goto(-100,-100)
 6 pendown()
 7 begin_fill()
 8 pencolor('black')
 9 fillcolor('black')
10 circle(100*2**0.5,steps = 4)
11 end_fill()
12 
13 left(45)
14 penup()
15 goto(0,-100)
16 pendown()
17 pensize(2)
18 pencolor('red')
19 begin_fill()
20 fillcolor('red')
21 circle(100,steps = 4)
22 end_fill()
23 
24 hideturtle()
25 done()

运行测试截图

task5.2

实验源码

 1 from turtle import *
 2 
 3 pensize(2)
 4 pencolor('blue')
 5 for i in range(5):
 6     setheading(90)
 7     r = 40+20*i
 8     goto(r,0)
 9     circle(r,extent = 90)
10     goto(0,0)
11 hideturtle()
12 done()

运行测试截图

实验任务6

task6

实验源码

 1 from turtle import *
 2 from random import random
 3 
 4 setup(800,600)
 5 def gen_color():
 6     return tuple((random() for i in range(3)))
 7 def rectangle():
 8     color(gen_color())
 9     begin_fill()
10     for i in range(2):
11         forward(5)
12         left(90)
13         forward(20)
14         left(90)
15     end_fill()
16 penup()
17 goto(-10*5,0)
18 pendown()
19 for k in range(20):
20     rectangle()
21     forward(5)
22 
23 hideturtle()
24 done()

运行测试截图

 

标签:10,20,range,源码,实验,import,def
From: https://www.cnblogs.com/siyi5981/p/17474870.html

相关文章

  • php文件上传之白名单00截断实验
    %00截断介绍:0x00,%00,/00在url中%00表示ascll码中的0,而ascii中0作为特殊字符保留,表示字符串结束,所以当url中出现%00时就会认为读取已结束。但是所谓的if拦截仍会读取后面的后缀达到绕过白名单的效果。当前版本环境:PHP版本低于5.4.24,或者PHP版本在5.5.8到5.6.0之间,且GPC......
  • 实验六
    实验任务一task1_1实验源码:1fromturtleimport*23defmove(x,y):4penup()5goto(x,y)6pendown()7defdraw(n,size=100):#绘制边长为size的正n边形8foriinrange(n):9fd(size)10left(360/n)11defmain():12......
  • Python实验课6
    实验任务一实验源码:fromturtleimport*defmove(x,y):penup()goto(x,y)pendown()defdraw(n,size=100):foriinrange(n):fd(size)left(360/n)defmain():pensize(2)pencolor('red')move(-200,0)......
  • 实验六
    实验1task1.1实验源码1fromturtleimport*23defmove(x,y):4penup()5goto(x,y)6pendown()78defdraw(n,size=100):9foriinrange(n):10fd(size)11left(360/n)1213defmain():14pensize(2)15......
  • 实验七
    任务一实验源码1classAccount:2'''一个模拟银行账户的简单类'''3def__init__(self,name,account_number,initial_amount=10):4'''构造新账户'''5self._name=name6self._c......
  • 实验六
    任务一实验源码1fromturtleimport*23defmove(x,y):4penup()5goto(x,y)6pendown()78defdraw(n,size=100):9foriinrange(n):10fd(size)11left(360/n)1213defmain():14pensize(2)15......
  • 实验六
    实验任务一实验源码:fromturtleimport*defmove(x,y):penup()goto(x,y)pendown()defdraw(n,size=100):foriinrange(n):fd(size)left(360/n)defmain():pensize(2)pencolor('red')move(-200,0)......
  • 实验七
    task4#define_CRT_SECURE_NO_WARNINGS#include<stdio.h>intmain(){charch;FILE*fp;inti=0;fp=fopen("data4.txt","r");ch=fgetc(fp);while(ch!=EOF){if(ch!=''&......
  • 实验6
    task1fromturtleimport*defmove(x,y):penup()goto(x,y)pendown()defdraw(n,size=100):foriinrange(n):fd(size)left(360/n)defmain():pensize(2)pencolor('red')move(-200,0)draw(3......
  • 实验六
    实验任务一实验源码:fromturtleimport*defmove(x,y):penup()goto(x,y)pendown()defdraw(n,size=100):foriinrange(n):fd(size)left(360/n)defmain():pensize(2)pencolor('red')move(-200,0)......