条件、循环、函数定义、字符串操作
2017-09-13 21:30
363 查看
2-a.用循环画五角星
2-b用循环画同心圆
2-c.用while循环画太阳花
2-d.用函数定义画五个五角星
import turtle
turtle.bgcolor('red')
turtle.color('yellow')
turtle.fillcolor('yellow')
def guo_goto(x,y): #定义位置
turtle.up()
turtle.goto(x,y)
turtle.down()
def guo_draw(x): #画星星
turtle.begin_fill()
for i in range(5):
turtle.forward(x)
turtle.right(144)
turtle.end_fill()
guo_goto(-300,200) #大星星
guo_draw(170)
guo_goto(30,280)
guo_draw(60)
guo_goto(120,200)
guo_draw(60)
guo_goto(120,126)
guo_draw(60)
guo_goto(30,60)
guo_draw(60)
2-e用函数定义画钻石花瓣的太阳花
3-1.输入学号,识别年级、专业、序号。
3-2.输入1-7的数字,输出对应的“星期几”。
识别身份证号中的省市区、年龄、性别。
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 turtle import* color('red','yellow') begin_fill() while True: forward(200) left(170) if abs(pos())<1: break end_fill() done()
2-d.用函数定义画五个五角星
import turtle
turtle.bgcolor('red')
turtle.color('yellow')
turtle.fillcolor('yellow')
def guo_goto(x,y): #定义位置
turtle.up()
turtle.goto(x,y)
turtle.down()
def guo_draw(x): #画星星
turtle.begin_fill()
for i in range(5):
turtle.forward(x)
turtle.right(144)
turtle.end_fill()
guo_goto(-300,200) #大星星
guo_draw(170)
guo_goto(30,280)
guo_draw(60)
guo_goto(120,200)
guo_draw(60)
guo_goto(120,126)
guo_draw(60)
guo_goto(30,60)
guo_draw(60)
2-e用函数定义画钻石花瓣的太阳花
import turtle turtle.color('green') while True: turtle.forward(100) turtle.left(50) turtle.forward(200) turtle.left(130) turtle.forward(100) turtle.left(50) turtle.forward(210) turtle.right(20) if abs(turtle.pos())<1: break turtle.done()
3-1.输入学号,识别年级、专业、序号。
a=input('输入你的学号:') print(a[:]) if len(a)>12: print('学号不存在!') print('年级:'+a[0:4]) print('专业:'+a[4:8]) print('序号:'+a[8:12])
3-2.输入1-7的数字,输出对应的“星期几”。
a=input('今天是星期几?') if a=='1': print('星期一') elif a=='2': print('星期二') elif a=='3': print('星期三') elif a=='4': print('星期四') elif a=='5': print('星期五') elif a=='6': print('星期六') else: print('星期日')
识别身份证号中的省市区、年龄、性别。
相关文章推荐
- 条件、循环、函数定义、字符串操作练习
- 条件、循环、函数定义、字符串操作练习
- 条件,循环,函数定义,字符串小练习
- 关于动态存储分配函数的调用,在已经过排序的数组中查找及删除内容的操作,余数的分析,删除字符数组中的空格,对链表的逆置,在源字符串中查找子字符串的个数,函数指针以及函数的调用,循环赋值带来的问题以及插入
- 定义一个长度大于5,包含字符‘@’的字符串,完成如下操作......(foreach及各种函数的用法)
- 【微软100题】定义字符串的左旋转操作:把字符串前面的若干个字符移动到字符串的尾部。 如把字符串abcdef左旋转2位得到字符串cdefab。请实现字符串左旋转的函数。
- 【微软100题】定义字符串的左旋转操作:把字符串前面的若干个字符移动到字符串的尾部。 如把字符串abcdef左旋转2位得到字符串cdefab。请实现字符串左旋转的函数。
- 二叉链表的定义与基本操作实现函数
- 你会用字符串操作函数吗?
- 编写一个函数reverse_string(char * string) 实现:将参数字符串中的字符反向排列。 要求:不能使用C函数库中的字符串操作函数
- oracle练习5-操作字符串的函数
- 一些字符串及内存操作函数的实现
- oracle字符串分割和提取函数定义
- 循环队列的定义、入队、出队等操作 C++代码实现
- Js字符串操作函数大全
- python字符串内建函数操作实例(cmp、str、enumerate、zip等)
- JavaScript中常见的字符串操作函数及用法
- 3.PHP条件语句及其字符串相关函数
- 驱动开发 常用字符串操作函数
- C语言字符串操作函数