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

 

转载于:https://www.cnblogs.com/crx234/p/8620926.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值