pyhton实验课2

2.1
x1,y1=1.2,3.57
x2,y2=2.26,8.7
print('x1={},y1={}'.format(x1,y1))
print('x2={},y2={}'.format(x2,y2))
print ('x1={:.1f},y1={:.1f}'.format(x1,y1))
print ('x2={:.1f},y2={:.1f}'.format(x2,y2))
print('x1={:<15},y1={:<15}'.format(x1,y1))
print('x2={:<15},y2={:<15}'.format(x2,y2))
print('x1={:-^40}'.format(x1))


2.2
x=input()
y=x.upper()
z=y.replace('A','')
print(x)

 


2.3
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


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

2.5
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!'''
lines=('0') #行数
a=('0') #单词数
b=('0') #字符数
c=('0') #空格数

lines=(len(text.splitlines()))
a1=(len(text.split()))
for space in text:
if space ==' ':
c=int(c)+1


print ('python 之禅的行数为',lines)
print ('python 之禅的单词数为',a1)
print ('python 之禅的字符数为',b)
print ('python 之禅的空格数为',c)

6.
wishs=[]
a=1
while(a<4):
x=input('请输入想要加入愿望清单的事情')
wishs.append(x)
a+=1
print ('{:-^50}'.format('我的愿望清单'))
n=1
for w in wishs:
print(f'{n}:{w}')
n+=1

 

posted @ 2021-04-05 14:41  阿巴阿巴阿巴巴啊  阅读(14)  评论(0)    收藏  举报