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

     1 impo sys
     2 print(sys.argv)
     3 import turtle
     4 turtle.bgcolor('red')
     5 turtle.color('yellow')
     6 turtle.fillcolor('yellow')
     7 turtle.setup(600,400,0,0)
     8 
     9 def moveto(x,y):
    10     turtle.up()
    11     turtle.goto(x,y)
    12     turtle.down()
    13 
    14 def print(n):
    15     turtle.begin_fill()
    16     for i in range(5):
    17         turtle.forward(n)
    18         turtle.right(144)
    19     turtle.end_fill()
    20 
    21 moveto(-260,120)
    22 turtle.begin_fill()
    23 for i in range(5):
    24     turtle.forward(120)
    25     turtle.right(144)
    26 turtle.end_fill()
    27 
    28 moveto(-120,160)
    29 turtle.left(31)
    30 print(40)
    31 turtle.setheading(0)
    32 
    33 moveto(-80,130)
    34 turtle.left(-18)
    35 print(40)
    36 turtle.setheading(0)
    37 
    38 moveto(-80,70)
    39 turtle.left(0)
    40 print(40)
    41 
    42 
    43 moveto(-120,20)
    44 turtle.left(31)
    45 print(40)
    46 turtle.hideturtle()
    47 turtle.done()

    运行结果图如下:

    网址:

    http://news.gzcc.cn/html/2017/xiaoyuanxinwe 
    n_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.ht 
    ml

    产生python文档的网址

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

    运行结果:

    网址:

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

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

    add3='http://news.gzcc.cn/html/xiaoyuanxinwen/'
    add4='.html'
    for i  in range(4):
        result=add3+str(i)+add4
        print(result)

    练习字符串内建函数: 
    strip,lstrip,rstrip,split,count

    用函数得到校园新闻编号

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

    用函数统计一歌词中单词出现的次数

    str=“Sometimes it's hard to define 
     If falling stars are hiding in your eyes Just watching you made me cry
    Cause now I know you'll never ever get off my mind 
    I never thought all those beautiful words can't describe 
    A little of your kindness, a bit of your light 
     There's nothing I can't give up for your smile 
     Whatever it takes, I'll make it alright. ”
    print(str.count('I'))
  • 相关阅读:
    whatweb tree
    testUrl
    ParseUrl
    whatweb wordpress.rb
    LeetCode: Binary Tree Level Order Traversal 解题报告
    LeetCode: Minimum Path Sum 解题报告
    Lintcode: Sort Colors II 解题报告
    LeetCode: Validate Binary Search Tree 解题报告
    LeetCode: Longest Common Prefix 解题报告
    LeetCode: Maximum Subarray 解题报告
  • 原文地址:https://www.cnblogs.com/crx234/p/8620926.html
Copyright © 2011-2022 走看看