2018-07-18 day 3 作业

在做下面的每个练习时,都编写一个独立的程序,并将其保存为名称类似于name_cases.py的文件
2-3 个性化消息: 将用户的姓名存到一个变量中,并向该用户显示一条消息。显示的消息应非常简单,如“Hello Eric, would you like to learn some Python today?”。

答:

name='eirc'
print('hello %s,would you like to learn some Python today?'%(name))
--->hello eirc,would you like to learn some Python today?


image.png

2-4 调整名字的大小写: 将一个人名存储到一个变量中,再以小写、大写和首字母大写的方式显示这个人名。

答:

name='pXL'
new_name1=name.lower()
print(new_name1)#--->pxl
new_name2=name.upper()
print(new_name2)#--->PXL
new_name3=name.capitalize()
print(new_name3)#--->Pxl


image.png

2-5 名言: 找一句你钦佩的名人说的名言,将这个名人的姓名和他的名言打印出来。输出应类似于下面这样(包括引号):Albert Einstein once said, “A person who never made a mistake never tried anything new.”

答:

str1='Albert Einstein once said,"to be or not to be"'
print(str1)#--->Albert Einstein once said,"to be or not to be"


image.png

2-6 名言2: 重复练习2-5,但将名人的姓名存储在变量famous_person 中,再创建要显示的消息,并将其存储在变量message 中,然后打印这条消息。

答:

famous_person='Albert Einstein'
message='"to be or not to be"'
print(message)#--->"to be or not to be"


image.png

2-7 剔除人名中的空白: 存储一个人名,并在其开头和末尾都包含一些空白字符。务必至少使用字符组合"\t" 和"\n" 各一次。 打印这个人名,以显示其开头和末尾的空白。然后,分别使用剔除函数lstrip() 、rstrip() 和strip() 对人名进行处理,并将结果打印出来。

答:

name='pxl'
new_name1='\npxl'
print(new_name1)#--->$$

pxl$$

new_name2='p\txl'
print(new_name2)#--->p xl
new_name3=name.lstrip('') print(new_name3)#--->pxl$$ new_name4=name.rstrip('')
print(new_name4)#--->$$pxl
new_name5=name.strip('$')
print(new_name5)#--->pxl

image.png

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 7,448评论 0 10
  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 9,891评论 0 23
  • 酿辣椒是我在家时最爱的一道莱,那时总是妈妈做,而现在我也成了家 ,今天也为我的孩子做了这道酿辣椒。 所需材料:前腿...
    全永州阅读 596评论 0 0
  • 这个九月 很好的开始吧… 付了欧蓝德的定金
    溦历阅读 301评论 0 0
  • 游泳池的五米跳台上,站着一个长相英俊,身材匀称的年轻男人。泳池边的人等待着欣赏帅哥跳水,只有站在他背后的两个朋友注...
    Morose阅读 582评论 0 2