实验二

#task1.py
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))

实验二

 

 format( ) 方法对输出数据进行格式化:

1.{:-^  t}:宽度占 t  列,居中对齐,空白处用 - 补齐;

2.{:.nf}:控制小数输出精度,保留n位小数;

3.{:<m}:控制数据输出宽度占m列,左对齐,空白处默认补空格。

 

#task2.py
string = input("请输入一段字符串:") str1 = string.replace("a","") str2 =str1.upper() print(str2)

 

实验二

 

#task3.py
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

 

实验二

 

#task4.py
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+=1

 

实验二

 

#task5.py
test = '''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("行数:",len(test.splitlines()))
print("单词数:",len(test.split()))
print("字符数:",len(test))
print("空格数:",test.count(' '))

 

实验二

 


#task6.py
t = [] i = 0 while i<3: x = input("输入想要加入愿望清单的事情:") t.append(x) i+=1 print('{:-^50}'.format("我的愿望清单")) n = 1 for dream in t: print(f'{" "}{n}.{dream}') n+=1

 

实验二

 

实验总结:

1.本次实验内容相较于上次,有了一定的灵活性综合性;

2.难度不大,都是一些基础知识的应用,不过值得一练,还学到了一些格式的设置;

3.第六个任务确实点了我一下,这学期事太多,已经很久没有想想自己的愿望了实验二

 

4.夢に向かって飛べ‼

 

上一篇:苹果Mac强大的批量重命名工具:A Better Finder Rename


下一篇:Jinja2 for better Ansible(渲染文件中配置项到template模板配置文件中)