Pycharm开发环境设置与熟悉。

本文介绍了Python编程的基础知识,包括基本输入输出、条件与循环语句的使用,以及字符串操作等,并通过绘制五星红旗的实例加深理解。

练习基本输入输出:

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

 

转载于:https://www.cnblogs.com/BOXczx/p/8619333.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值