条件、循环、函数定义 练习

a.五角星

import turtle
turtle.color(‘yellow‘)
turtle.begin_fill()
for i in range(5):
turtle.forward(100)
turtle.right(144)
turtle.end_fill()

b.同心圆

import turtle
for i in range(5):
turtle.up()
turtle.goto(0,-20*(i+1))
turtle.down()
turtle.circle(20*(i+1))

c.太阳花

from turtle import*
speed(40)
color(‘red‘,‘yellow‘)
begin_fill()
while True:
forward(300)
left(179)
if(abs(pos()))<1:
break
end_fill()
done()

d.五个五角星

import turtle
turtle.setup(600,400,0,0)
turtle.color(‘yellow‘)
turtle.bgcolor(‘red‘)
turtle.fillcolor(‘yellow‘)

def my_goto(x,y):
turtle.up()
turtle.goto(x,y)
turtle.down()

def my_draw5(r):
turtle.begin_fill()
for i in range(5):
turtle.forward(r)
turtle.right(144)
turtle.end_fill()

my_goto(-360,190)

my_draw5(100)
my_goto(-155,240)
my_draw5(50)
my_goto(-90,165)
my_draw5(50)
my_goto(-75,85)
my_draw5(50)
my_goto(-120,50)
my_draw5(50)

e.画菱形太阳花

import turtle

def draw_center(brad):
brad.forward(125)
brad.right(45)
brad.forward(100)
brad.right(135)

def draw_flower():

window=turtle.Screen()
window.bgcolor(‘blue‘)

brad=turtle.Turtle()
brad.color(‘yellow‘)
brad.speed(20)

for i in range(1,18):
draw_center(brad)
draw_center(brad)
brad.left(20)

brad.right(70)
brad.forward(325)

window.exitonclick()

draw_flower()
turtle.hideturtle()

时间: 2024-08-06 07:56:39

条件、循环、函数定义 练习的相关文章

阶乘循环--函数定义、函数调用

#! /bin/bash # using recursion function factorial() { if [ $1 -eq 1 ]; then echo 1 else local temp=$[ $1 -1 ] local result=`factorial $temp` echo $[ $result * $1] fi } read -p "Enter value:" value result=`factorial $value` echo "The factori

make--变量 条件判断 函数定义及调用

一.变量的高级主题 A.变量值的替换1.使用指定字符(串)替换变量中的后缀字符(串)2.语法格式:$(var:a=b) (将a替换成b)a.替换表达式中不能有任何的空格b.make中支持使用${}对变量进行取值示例 src:=a.cc b.cc c.cc obj:=$(src:cc=o) test: @echo "obj=>$(obj)" 输出结果由上图可以看出变量值的替换B.变量的模式替换1.使用%保留变量值中的指定字符,替换其它字符2.语法格式:$(var:a%b=x%y)a

条件循环函数练习

1.五角星import turtle turtle.setup(600,400,0,0) turtle.color('yellow') turtle.bgcolor('red') turtle.fillcolor('yellow') turtle.up() turtle.goto(-250,75) turtle.down() turtle.begin_fill() for i in range(5): turtle.forward(100) turtle.right(144) turtle.en

条件、循环、函数定义、字符串操作练习

注意标准库的两种导入与使用方式,建议大家采用<库名>.<函数名>的方式. 对前面的代码进行优化,用for,while,if,def实现: 用循环画五角星 1 import turtle 2 3 turtle.fillcolor("red") 4 turtle.begin_fill() 5 for i in range(5): 6 turtle.forward(100) 7 turtle.right(144) 8 turtle.end_fill() 用循环画同心圆

条件、循环、函数定义

1.用循环画五角星 import turtle turtle.setup(600,400,0,0) turtle.color("yellow") turtle.bgcolor('red') turtle.fillcolor("yellow") turtle.up() turtle.goto(-250,75) turtle.down() turtle.begin_fill() for i in range(5): turtle.forward(100) turtle.

条件、循环、函数定义等练习

对前面的代码进行优化,用for,while,if,def实现: 用循环画五角星 用循环画同心圆 用while循环画太阳花 用函数定义画五个五角星 用函数定义画钻石花瓣的太阳花 字符串操作 输入学号,识别年级.专业.序号. 输入1-7的数字,输出对应的"星期几". 识别身份证号中的省市区.年龄.性别. 用循环画五角星 import turtle turtle.fillcolor('yellow') turtle.begin_fill() for i in range (5): turtl

条件、循环、函数定义、字符串操作

2-a.用循环画五角星 import turtle for i in range(5): turtle.forward(200) turtle.left(144) 2-b用循环画同心圆 import turtle turtle.color('green') for i in range(4): turtle.up() turtle.goto(0,-40*(i+1)) turtle.down() turtle.circle(40*(i+1)) 2-c.用while循环画太阳花 from turtl

条件,循环,函数定义,字符串小练习

用for,while,if,def实现 1.用循环画五角星 1 from turtle import * 2 for i in range(5): 3 forward(110) 4 right(144) 2.用循环画同心圆 1 from turtle import * 2 for i in range(5): 3 pu() 4 goto(0,-(i+1)*10) 5 pd() 6 circle((i+1)*10) 3.用wlile循环画太阳花 1 color('red','yellow') 2

【作业】条件、循环、函数定义、字符串操作练习

一.注意标准库的两种导入与使用方式,建议大家采用<库名>.<函数名>的方式. 二.对前面的代码进行优化,用for,while,if,def实现: 1.用循环画五角星 1 from turtle import* 2 color("red") 3 fillcolor("red") 4 begin_fill() 5 while True: 6 forward(200) 7 right(144) 8 if abs(pos())<1: 9 bre

条件、循环、函数定义、字符串操作练习9-14

用循环画五角星 >>> import turtle >>> for i in range(5): turtle.forward(100) turtle.right(144) 用循环画同心圆 >>> import turtle >>> for i in range(4): turtle.penup() turtle.goto(0,-40*i) turtle.pendown() turtle.circle(40*i)   用while循环