Python Basic Synthesis exercise

Source: Internet
Author: User

1. Comprehensive exercise: Draw one side of the flag, put the code with the run Publish blog to hand in the homework.

The code is as follows:

1 ImportTurtle2 3 defMygoto (x, y):4 turtle.up ()5 Turtle.goto (x, y)6 Turtle.down ()7 8 defDrow (x):9 Turtle.begin_fill ()Ten      forIinchRange (5): One Turtle.forward (x) ATurtle.right (144) - Turtle.end_fill () -  theTurtle.setup (600,400, 0,0) -Turtle.color ("Yellow") -Turtle.bgcolor ("Red") -Turtle.fillcolor ("Yellow") +  -Mygoto ( -250,95) +Drow (100) A  at  forIinchRange (4): -X=1 -Turtle.right (5) -     ifIinch[0,3]: -x=0 -Mygoto ( -135+x*30,155-i*45) inTurtle.left (20-i*15) -Drow (30) to  + Turtle.hideturtle () -Turtle.done ()

2. String Exercises:

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

Get the campus news number, code and the following:

2.1:

str = "http://news.gzcc.cn/html/2017/xiaoyuanxinwen_1027/8443.html" num = Str.rstrip (". html"). Split ("_") [1]print ( Num

  

2.2

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

Generate URLs for Python documents

str1 = "https://docs.python.org/3.6/library/" STR2 = ". html" str =str1+ "turtle" +str2print (str)

  

2.3

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

A series of news page URLs that generate campus news, with the following code:

For I in Range (2,10):  str = "http://news.gzcc.cn/html/xiaoyuanxinwen/{}.html". Format (i)  print (str)

  

3. Practice string built-in function: Strip,lstrip,rstrip,split,count,replace

3.1

Use the function to get the campus news number, code and the following:

str1 = "http://news.gzcc.cn/html/xiaoyuanxinwen/{}.html" For I in range (2, ten):    str2 = Str1.format (i)    STR3 = str2 . Rstrip (". html"). Split ("/") [-1]    print (STR3)

  

3.2

Use the function to count the number of words appearing in lyrics (articles, novels), replace punctuation with spaces, and use spaces for word segmentation. The code is as follows:

str = ' Every night in my dreams,i see you. I feel you. That's how I know to go on. Far across the distance,and spaces between usyou has come to show your go on.  Near, far, wherever-arei believe that the heart does go ononce more you open the Doorand your ' re here in my heartand my  Heart'll go on and onlove can touch us one timeand last for a lifetimeand never go till we ' re gonelove is when I loved  Youone true Time I hold toin my life we'll always go onnear, far, wherever you arei believe that the heart does go ononce More your open the Doorand you ' re here in my heartand my heart would go on and Onyou ' re here, there's nothing I fear,and I Know that my heart would go onwe ' ll stay forever this wayyou is safe in my heartand my heart would go on and O ' Print (str. Count ("my")) Print (Str.count ("Heart")) Print (Str.count ("Go")) Print (Str.count ("on")) Print (Str.replace (",", ""))

  

Python basic synthesis exercise

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.