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())
    

      

  • 相关阅读:
    浅入浅出---JQuery究竟是什么?
    How far away ?(DFS)
    SoC嵌入式软件架构设计之七:嵌入式文件系统设计
    Java Log Viewer日志查看器
    软件測试基本方法(三)之黑盒測试
    NLP1 —— Python自然语言处理环境搭建
    个性化搜索的几个阶段
    自然语言处理扫盲·第四天——白话人机问答系统原理
    自然语言处理扫盲·第三天——白话情感分析原理
    自然语言处理扫盲·第二天——白话机器翻译原理
  • 原文地址:https://www.cnblogs.com/lgy520/p/8609932.html
Copyright © 2011-2022 走看看