条件循环函数练习

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.end_fill()

2.同心圆

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

3.太阳花

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

4.五星红旗

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

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

mygoto(-250,75)

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

mygoto(-100,150)

turtle.begin_fill()
for i in range(5):
turtle.forward(50)
turtle.right(144)
turtle.end_fill()

mygoto(-80,80)
turtle.begin_fill()
for i in range(5):
turtle.forward(50)
turtle.right(144)
turtle.end_fill()

mygoto(-90,20)
turtle.begin_fill()
for i in range(5):
turtle.forward(50)
turtle.right(144)
turtle.end_fill()

mygoto(-110,-50)
turtle.begin_fill()
for i in range(5):
turtle.forward(50)
turtle.right(144)
turtle.end_fill()

				
时间: 2024-08-25 11:16:56

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

循环 函数 软件包 【中】

循环 函数 软件包  [中] 创建无限循环 while true; do 循环体 done until false; do 循环体 Done 特殊用法 while循环的特殊用法(遍历文件的每一行): while read line; do 循环体 done < /PATH/FROM/SOMEFILE 依次读取/PATH/FROM/SOMEFILE文件中的每一行,且将 行赋值给变量line 示例 [[email protected] bin]# bash wenben.sh #! # read -

Python基础教程之第5章 条件, 循环和其它语句

Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)] on win32 #Chapter 5 条件, 循环和其它语句 #5.1 print和import的很多其它信息 #对于非常多应用程序来说, 使用logging模块记日志比print语句更合适 #5.1.1 使用逗号输出 #能够看到, 每隔參数之间都自己主动插入了一个空格符 >>> print 'Age:',42 Age: 42 >&g

python学习笔记七:条件&循环语句

1.print/import更多信息 print打印多个表达式,使用逗号隔开 >>> print 'Age:',42 Age: 42   #注意个结果之间有一个空格符 import:从模块导入函数 import 模块 from 模块 import 函数 from 模块 import * 如果两个模块都有open函数的时候, 1)使用下面方法使用: module1.open()... module2.open()... 2)语句末尾增加as子句 >>> import ma

python3_04.循环&函数

1.循环&条件控制 注意: 每个条件后面要使用冒号(:),表示接下来是满足条件后要执行的语句块. 使用缩进来划分语句块,相同缩进数的语句在一起组成一个语句块. break 语句可以跳出 for 和 while 的循环体. continue语句被用来告诉Python跳过当前循环块中的剩余语句,然后继续进行下一轮循环. pass是空语句,是为了保持程序结构的完整性.pass 不做任何事情,一般用做占位语句. 循环技巧: 在字典中循环时,关键字和对应的值可以使用 items() 方法同时解读出来 在序

Linux python3安装/shell脚本/if/循环/函数

python3安装 安装过程 安装包: wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tgztar -xvf Python-3.7.0.tgz #解压 基础包 1.基础yum包 yum install gcc yum install zlib yum install zlib-devel yum install libffi-devel -y yum install openssl openssl-devel -y 检测平台:

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

#! /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

Java语言中的----条件循环

day06 Java语言中的条件循环 一.条件循环概述: 条件循环对于我们来说一点也不陌生,在程序中使用循环语句是很普片的事儿,所以说你一定得学会循环语句. 二.条件循环 条件循环主要包括两个循环语句,分别是if...else和switch...case语句. 1.if循环结构         if (){                  }else{                  } 2.switch...case循环结构         switch () {     case 1:

Java语句中的----条件循环

day06 Java语言中的条件循环 一.条件循环概述: 条件循环对于我们来说一点也不陌生,在程序中使用循环语句是很普片的事儿,所以说你一定得学会循环语句. 二.条件循环 条件循环主要包括两个循环语句,分别是if...else和switch...case语句. 1.if循环结构         if (){                  }else{                  } 2.switch...case循环结构         switch () {     case 1:

day01:python之while条件循环

continue:  break:  一次性跳出多次嵌套循环:  while+else  while条件循环: