MYXHH

导航

 

任务一

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))

  

 

 任务二

s=input()
s=s.replace('a','')
print(s.upper())

  

 

 任务三

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

  

 

 #print行与n=n+1行前用tab缩进

任务四

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

  

 

 任务五

 

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

  

 

#"可正常运行,'无法正常运行

 

任务六

a=input('输入想要加入愿望清单的事情:')
b=input('输入想要加入愿望清单的事情:')
c=input('输入想要加入愿望清单的事情:')
print('{:-^50}'.format('我的愿望清单'))
print(f'1:{a}')
print(f'2:{b}')
print(f'3:{c}')

  

 总结:对字符串处理更了解,会尝试一些更复杂的方法去处理问题

尚存的问题:对标点符号的使用不理解

posted on 2021-04-02 18:18  MYXHH  阅读(39)  评论(1)    收藏  举报