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


      1. 用循环画五角星
        import turtle
        turtle.color ('red')
        turtle.fillcolor ('yellow')
        turtle.begin_fill ()
        for i in range (5):
            turtle.forward (100)
            turtle.right (144)
        turtle.end_fill ()
      2. 用循环画同心圆
        import turtle
        from turtle import *
        for i in range(10):
            turtle.up ()
            turtle.goto(0,-20*(i+1))
            turtle.down ()
            turtle.circle(20*(i+1))
      3. 用while循环画太阳花
        import turtle
        from turtle import *
        while True:
            forward(200)
            right(170)
            if(abs(pos()))<1:
                break
      4. 用函数定义画五个五角星
        import turtle
        turtle.color ('red')
        turtle.bgcolor ('red')
        turtle.color ('yellow')
        turtle.fillcolor ('yellow')
        def lcm_draw5(r):
            turtle.begin_fill ()
            for i in range(4):
                turtle.forward (r)
                turtle.right (144)
            turtle.end_fill()
        def lcm_location(x,y):
            turtle.up ()
            turtle.goto(x,y)
            turtle.down ()
        lcm_location(-250,75)
        lcm_draw5(100)
        
        
        lcm_location(-80,125)
        lcm_draw5(50)
        
        
        lcm_location(-60,100)
        lcm_draw5(50)
        
        lcm_location(-80,-20)
        lcm_draw5(50)
        
        lcm_location(-70,-60)
        lcm_draw5(50)
      5. 用函数定义画钻石花瓣的太阳花
        import turtle
        def lcm_draw4():
            turtle.forward(100)
            turtle.right(45)
            turtle.forward(100)
            turtle.right(135)
        
        for i in range(36):
            lcm_draw4()
            lcm_draw4()
            turtle.left(10)
    1. 字符串操作
      1. 输入学号,识别年级、专业、序号。
        num=input('输入您的学号:')
        print('年级:'+num[:4] ,'专业:'+num[4:8], '序号:'+num[8:])
      2. 输入1-7的数字,输出对应的“星期几”。
        s=('一二三四五六日')
        day=int(input('输入数字(1-7):'))
        print('星期'+s[day-1])
      3. 识别身份证号中的省市区、年龄、性别。
      4. 用字符串操作生成python文档各库的网址(起始网址在这里https://docs.python.org/3.6/library/index.html)
        a=('https://docs.python.org/3.6/library/')
        b=('.html')
        print(a[:]+'index'+b[:])
  • 相关阅读:
    当数据库结构改变时,需要将数据库删除再创建
    命名空间“System.Web.Mvc”中不存在类型或命名空间“Ajax”(是否缺少程序集引用?)
    jqGrid 各种参数 详解
    二维数组最小路径和
    动态规划:最大连续子序列和
    最长递增子序列
    java单例模式的几种实现
    java多线程的实现方法
    sleep与wait的区别
    数组旋转
  • 原文地址:https://www.cnblogs.com/lcm1995/p/7522222.html
Copyright © 2020-2023  润新知