代码改变世界

作业

2017-09-20 20:57  019王泽  阅读(169)  评论(0)    收藏  举报

1.实例: 下载一首英文的歌词或文章,将所有,.?!等替换为空格,将所有大写转换为小写,统计某几个单词出现的次数,分隔出一个一个的单词。

wei='''As a parent, you always think your child is the best ever -- that's just what parents do. But after seeing Kendall perform, I know she's one of the best, even though she didn't make it into the Top 24.Kendall is eighteen now, living every day to its fullest. She's recorded a CD with some of John Mellencamp's band members. She's also on CMT's Music City Madness for an original song and video, and is having some good success. I'm absolutely sure she's going to make it big some day. Kendall just puts it all in God's hands.When she was a little girl trying hard to be strong, she looked up at me, her big eyes brimming with tears, and asked me why she had to have Tourette's Syndrome. My heart ached to make the world right for my child. But I looked right back at her and told her the truth as I see it."Kendall, God gave you a pure heart, an angelic voice, a strong mind, and a beautiful presence. With all of that, he had to make it fair for everyone else."'''

wei=wei.lower()
for i in ',./':
wei=wei.replace(i,' ')
words=wei.split(' ')
print(wei)
print(wei.count('lang'))
print(wei.split(' '))

2.列表实例:由字符串创建一个作业评分列表,做增删改查询统计遍历操作。例如,查询第一个3分的下标,统计1分的同学有多少个,3分的同学有多少个等。

grade=list('123213123122')

for i in range(len(grade))

          grade[i]=(int(grade[i]))

print(grade)

print(grade.index(3))

print(grade.count(1))

print(grade.count(3))

3.简要描述列表与元组的异同。

列表是可以更改的,元组是不能更改的。