码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2017-09-14 11:54:27      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:orm   函数   time   星期六   abs   logs   done   import   字符串操作   

画五角星

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)

技术分享  

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

标签:orm   函数   time   星期六   abs   logs   done   import   字符串操作   

原文地址:http://www.cnblogs.com/55lsk/p/7519008.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!