zoukankan      html  css  js  c++  java
  • Python基础综合练习

    画一面五星红旗,将代码与运行截图发布博客交作业

    import turtle
    t = turtle.Pen();
    t.hideturtle()
    #移动笔
    def mygoto(x, y):
        t.up()
        t.goto(x, y)
        t.down()
    #画五角星
    def dramfive(x):
        t.begin_fill()
        for i in range(5):
            t.forward(x);
            t.right(144);
        t.end_fill();
    
    t.speed(5);
    t.pensize(1);
    #红色国旗
    t.color('red');
    mygoto(-300,250)
    t.begin_fill()
    for i in range(2):
        t.forward(600)
        t.right(90)
        t.forward(400)
        t.right(90)
    t.end_fill()
    
    #大五角星
    t.color('yellow');
    mygoto(-260,180)
    dramfive(120)
    
    #小五角星
    for i in range(4):
       x=1
       if i in[0,3]:
          x = 0
       mygoto(-120+x*40,220-i*40)
       t.left(15-i*15)
       dramfive(30)
    
    turtle.done();
    

    http://news.gzcc.cn/html/2017/xiaoyuanxinwen_1027/8443.html

    取得校园新闻的编号

    str1 ="http://news.gzcc.cn/html/2017/xiaoyuanxinwen_1027/8443.html"
    print(str1[-9:-5])
    

    https://docs.python.org/3/library/turtle.html

    产生python文档的网址

    str2 ="https://docs.python.org/3/library/turtle.html"
    print(str2.replace("turtle","python"))
    

    http://news.gzcc.cn/html/xiaoyuanxinwen/4.html

    产生校园新闻的一系列新闻页网址

    area1 = "http://news.gzcc.cn/html/xiaoyuanxinwen/"
    area2 = ".html"
    for i in range(2,10):
       area = area1 + str(i) + area2
       str3 = "http://news.gzcc.cn/html/xiaoyuanxinwen/{}.html".format(i)
       print(str3,area)
    

    用函数得到校园新闻编号

    str4 ="http://news.gzcc.cn/html/2017/xiaoyuanxinwen_1027/8443.html"
    print (str4.split('_',2)[1].rstrip(".html"))
    

    用函数统计一歌词(文章、小说)中单词出现的次数,替换标点符号为空格,用空格进行分词。

    str5 = '''You do the Hokey Pokey and you turn yourself around.
     That‟s what it‟s all about.
     You put your right foot in, you put your right foot out.
     You put your right foot in, and you shake it all about.
     You do the Hokey Pokey and you turn yourself around.
     That‟s what it‟s all about.
     You put your left foot in, you put your left foot out.
     You put your left foot in, and you shake it all about.
     You do the Hokey Pokey and you turn yourself around.
     That‟s what it‟s all about.
     You put your whole self in, you put your whole self out.
     You put your whole self in, and you shake it all about.
     You do the Hokey Pokey and you turn yourself around.
     That‟s what it‟s all about.'''
    
    print(str5.count("you"));
    print(str5.replace("."," "))
    print(str5.split())
    

      

  • 相关阅读:
    唐寅 《桃花庵歌》
    asp.net 后台隐藏div
    dataset的用法
    C#中的DateTime类型加减
    discuz! x2.5 文章添加分享按钮
    asp.net学习小网站
    table固定行和表头
    aspx.net开源的画图组件
    Global.asax详解
    int.Parse() int.TryParse
  • 原文地址:https://www.cnblogs.com/lgy520/p/8609932.html
Copyright © 2011-2022 走看看