Python基础练习
import turtle def mygoto(x,y): turtle.up() turtle.goto(x,y) turtle.down() def drawWz(r): turtle.begin_fill() for i in range(5): turtle.forward(r) turtle.right(144) turtle.end_fill() turtle.setup(600,400,0,0) turtle.color("yellow") turtle.bgcolor("red") turtle.fillcolor("yellow") mygoto(-210,100) drawWz(100) for i in range(4): x=1 if i in [0,3]: x=0 mygoto(-78+x*45,150-i*40) turtle.left(15-i*15) drawWz(30) mygoto(0,0) turtle.hideturtle() turtle.done()
用函数统计一歌词(文章、小说)中单词出现的次数,替换标点符号为空格,用空格进行分词。
str = ''' I've been reading books of old The legends and the myths Achilles and his gold Hercules and his gifts Spiderman's control And Batman with his fists And clearly I don't see myself upon that list She said where'd you wanna go How much you wanna risk I'm not looking for somebody With some Superhuman gifts Some Superhero Some fairytale bliss Just something I can turn to Somebody I can kiss I want something just like this Doo doo doo doo doo doo''' print(str.count("my")) print(str.count("you")) print(str.count("and")) print(str.count("kiss")) print(str.replace(","," "))