码迷,mamicode.com
首页 > 其他好文 > 详细

实验2

时间:2021-04-07 11:09:12      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:ati   The   for   exp   and   text   bre   code   能力   

1、实验内容1

 

def main():
    pass

if __name__ == __main__:
    main()
x1, y1 = 1.2, 3.57
x2, y2 = 2.26, 8.7
print({:-^40}.format(输出1))
print(x1 = {}, y1 = {}.format(x1, y1))
print(x2 = {}, y2 = {}.format(x2, y2))
print({:-^40}.format(输出2))
print(x1 = {:.1f}, y1 = {:.1f}.format(x1, y1))
print(x2 = {:.1f}, y2 = {:.1f}.format(x2, y2))
print({:-^40}.format(输出3))
print(x1 = {:<15}, y1 = {:<15}.format(x1, y1))
print(x2 = {:<15}, y2 = {:<15}.format(x2, y2))

技术图片技术图片

 

  通过自己敲击键盘,我对Python的format函数更加熟悉了,并且还发现了不同格式的format函数有各种新玩法。

2、实验内容2

 

def main():
    pass

if __name__ == __main__:
    main()
#task2.py
s=input(输入字符:)
print(s.upper().replace(A,‘‘))

技术图片技术图片

感觉自己写的代码老老实实,中规中矩吧,虽然没有用到很灵活的函数,但是简短了不少。

3、实验内容3

 

def main():
    pass

if __name__ == __main__:
    main()
name_list=[david bowie,louis armstrong,leonard cohen,bob dylan,
cocteau twins]

n=1
for name in name_list:
    print(f{n}: {name.title()})
    n +=1

技术图片

 技术图片

通过对实验内容3的编写,我发现Python在列表处理方面展现出了极其强大的数据处理能力以及便利性,也让我有了更大的兴趣去探索Python。

4、实验内容4

 

def main():
    pass

if __name__ == __main__:
    main()
name_list=[david bowie,louis armstrong,leonard cohen,bob dylan,
cocteau twins]

n=1
for name in name_list:
    print(f{n}. {name.title()})
    n +=1

技术图片

技术图片

 

相信只要看懂了实验内容3,这题并不难,同样,实现这种方式的代码有很多,Python还有很多有趣的东西等我们去探索。

5、实验内容5

 

def main():
    pass
if __name__ == __main__:
    main()
text=(‘‘‘The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren‘t special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you‘re Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it‘s a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let‘s do more of those!‘‘‘)
print( 行数:%s\n%len(text.splitlines()),单词数:%s\n%len(text.split()),
空格数:%s\n%text.count(‘‘),单词数:%s%len(text))

技术图片

技术图片

 

Python之禅可以说是Python的经典了,统计它的行数,单词数等等加深了我对这几个函数的理解。

6、实验内容6

 

def main():
    pass

if __name__ == __main__:
    main()
dream=[]
i=0
while i<=2:
    dream_list=input(输入想要加入愿望清单的事情:)
    dream.append(dream_list)
    i+=1
print({:-^50}.format(我的愿望清单))
n=1
for wish in dream:
    print(f{n}.{wish.title()})
    n+=1

技术图片

技术图片

 

结合前几个实验内容的练习,这题并不是很困难,当然“通向罗马的路不止一条”,我还会去探索出更多新奇的路线的。

 

实验2

标签:ati   The   for   exp   and   text   bre   code   能力   

原文地址:https://www.cnblogs.com/202013420034pjy/p/14620049.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!