Pycharm开发环境设置与熟悉。

练习基本输入输出:

print('你好,{}.'.format(name))

print(sys.argv)

 

库的使用方法:

import ...

from ... import ...

 

条件语句:

    if (abs(pos()))<1:

        break

 

循环语句:

for i in range(5):

while True:

 

函数定义:

def mygoto(x,y):

def drawjx(r):

 

综合练习:画一面五星红旗,将代码与运行截图发布博客交作业。

 

import turtle

def mygoto(x, y):
    turtle.up()
    turtle.goto(x, y)
    turtle.down()

def drawF(x):
    turtle.begin_fill()
    for i in range (5):
        turtle.forward(x)
        turtle.right(144)
    turtle.end_fill()

turtle.setup=(600, 400, 0, 0)
turtle.color("yellow")
turtle.bgcolor('red')
turtle.fillcolor("yellow")

mygoto(-270, 120)
drawF(120)

for i in range(4):
    x=1
    if i in [0, 3]:
        x=0
    mygoto(-120+x*30,150-i*40)
    turtle.left(15-i*15)
    drawF(30)

mygoto(0, 0)
turtle.hideturtle()
turtle.done()

 

字符串练习:

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

取得校园新闻的编号

 

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

 

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

产生python文档的网址

 

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

 

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

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

 

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

 

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

用函数得到校园新闻编号

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

 

str = '''
I'm hurting, baby, I'm broken down
I need your loving, loving, I need it now
When I'm without you
I'm something weak
You got me begging
Begging, I'm on my knees
I don't wanna be needing your love
I just wanna be deep in your love
And it's killing me when you're away
Ooh, baby,
'Cause I really don't care where you are
I just wanna be there where you are
And I gotta get one little taste
Your sugar
Yes, please
Won't you come and put it down on me
I'm right here, 'cause I need
Little love and little sympathy
Yeah you show me good loving
Make it alright
Need a little sweetness in my life
Your sugar
Yes, please
Won't you come and put it down on me
My broken pieces
You pick them up
Don't leave me hanging, hanging
Come give me some
When I'm without ya
I'm so insecure
You are the one thing
The one thing, I'm living for
I don't wanna be needing your love
I just wanna be deep in your love
And it's killing me when you're away
Ooh, baby,
'Cause I really don't care where you are
I just wanna be there where you are
And I gotta get one little taste
Your sugar
Yes, please
Won't you come and put it down on me
I'm right here, 'cause I need
Little love and little sympathy
Yeah you show me good loving
Make it alright
Need a little sweetness in my life
Your Sugar! (Your sugar!)
Yes, please (Yes, please)
Won't you come and put it down on me
Yeah
I want that red velvet
I want that sugar sweet
Don't let nobody touch it
Unless that somebody's me
I gotta be a man
There ain't no other way
'Cause girl you're hotter than southern California Bay
I don't wanna play no games
I don't gotta be afraid
Don't give all that shy shit
No make up on, that's my
Sugar
Yes, please
Won't you come and put it down on me (down on me!)
Oh, right here (right here),
'Cause I need (I need)
Little love and little sympathy
Yeah you show me good loving
Make it alright
Need a little sweetness in my life
Your sugar! (Sugar!)
Yes, please (Yes, please)
Won't you come and put it down on me
Your sugar
Yes, please
Won't you come and put it down on me
I'm right here, 'cause I need
Little love and little sympathy
Yeah you show me good loving
Make it alright
Need a little sweetness in my life
Your sugar
Yes, please
Won't you come and put it down on me
(Down on me, down on me)'''
print(str.count("sugar"))
print(str.replace(","," "))

 

posted on 2018-03-21 20:18  223陈子翔  阅读(607)  评论(0编辑  收藏  举报