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

实验二

时间:2021-04-05 12:32:08      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:lines   方式   rgb   for   rabl   mes   only   ace   plain   

task1

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={:.1f}".format(x1,y1))
print(x2={:<15},y2={:.1f}.format(x2,y2))

技术图片

 

 

task2

x=input("enter a str")
s=x.upper()
print(s.replace(A,‘‘))

技术图片

 

 task3

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=n+1

技术图片

 

 task4

name_list = [david bowie, louis armstrong, leonard cohen, bob dylan,
cocteau twins]
name_list=sorted(name_list)
n = 1
for name in name_list:
    print(f{n}.{name.title()})
    n=n+1

技术图片

 

  task5

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(f行数:{len(text.splitlines())})
print(f单词数:{len(text.split())})
print(f字符数:{len(text)})
print(f空格数:{text.count(" ")})

 

技术图片

 

 task 6

x=list()
for i in range(3):
    x.append(input(输入你的愿望))
print({:-^50}.format("我的愿望清单"))
for i in range(1,4):
    print(f{i}.{x[i-1]})

技术图片

 

 

实验总结

1.python中有许多表达方式,简洁值得学习

2.python可以帮助我们做很多事情

 

实验二

标签:lines   方式   rgb   for   rabl   mes   only   ace   plain   

原文地址:https://www.cnblogs.com/zhr123456/p/14613522.html

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