课堂练习(条件循环函数定义字符串操作)

Posted 55卢思凯

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了课堂练习(条件循环函数定义字符串操作)相关的知识,希望对你有一定的参考价值。

画五角星

import turtle for i in range(5): turtle.forward(200) turtle.right(144)

 

画同心圆

import turtle
for i in range(4):
    turtle.penup()
    turtle.goto(0,-40*i)
    turtle.pendown()
    turtle.circle(40*i)

  

画太阳花

import turtle
turtle.color(\'yellow\',\'red\')
turtle.speed(\'fastest\')
turtle.begin_fill()
while True:
    turtle.forward(150)
    turtle.left(200)
    if abs(turtle.pos())<1:
        break
turtle.end_fill()
turtle.done()

画五星红旗

import turtle turtle.setup(600,400,0,0) turtle.color("yellow") turtle.bgcolor("red") turtle.fillcolor("yellow") def yyj_goto(x,y): turtle.up() turtle.goto(x,y) turtle.down() def yyj_draw(r): turtle.begin_fill() for i in range(5): turtle.forward(r) turtle.right(144) turtle.end_fill() yyj_goto(-600,220) yyj_draw(150) yyj_goto(-400,295) yyj_draw(50) yyj_goto(-350,212) yyj_draw(30) yyj_goto(-350,145) yyj_draw(30) yyj_goto(-400,90) yyj_draw(30)

  

画钻石花

import turtle turtle.color("blue") for i in range(35): turtle.right(12) for i in range(2): turtle.forward(150) turtle.right(30) turtle.forward(100) turtle.right(150)

  

学号输入

def shibie(studentID): if len(studentID)<12: print("请输入正确的学号!") elif studentID.isdigit() != True: print("请输入正确的学号!") else: grade = studentID[0:4] profession = studentID[4:8] order = studentID[10:12] print("年级:{}级".format(grade)) if profession == "0611": print("专业:网络工程") print("序号:{}".format(order)) studentID = input("请输入学号:") shibie(studentID)

 

查看星期

def weekday(week): week=int(week) if 0<week<8: i=week-1 str=[\'星期一\',\'星期二\',\'星期三\',\'星期四\',\'星期五\',\'星期六\',\'星期日\'] print("数字{}是{}".format(week,str[i])) else: print("输入有误") week=input("输入1~7内的数字:") weekday(week)

 

 

输入身份证

import time #省份对应字典 provinces = { 44:\'广东省\', } def shibie(IDcard): province = IDcard[0:2] birthYear = IDcard[6:10] localYear = time.strftime(\'%Y\') age = int(localYear) - int(birthYear) sex = IDcard[16:17] print("省份为:",provinces.get(int(province))) print("年龄为:{}".format(age)) if int(sex) % 2 == 0: print("性别:女") else: print("性别:男") IDcard = input("请输入身份证:") shibie(IDcard)

  

以上是关于课堂练习(条件循环函数定义字符串操作)的主要内容,如果未能解决你的问题,请参考以下文章

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

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

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

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

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

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