• 微信公众号:美女很有趣。 工作之余,放松一下,关注即送10G+美女照片!

实验2练习

开发技术 开发技术 2周前 (04-07) 11次浏览
任务一
x1,y1=1.2,3.57
x2,y2=2.26,8.7
print("x1={:.1f},y1={:.1f}".format(x1,y1))
print("{:<15}".format(y2))
print("{:>15}".format(y2))
print("{:#^40}".format(x1))

实验2练习



任务二
s=input("请输入一个字符串n")
x=s.upper()
y=x.replace("A","")
print(y)

实验2练习


任务三
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练习


任务四

name_list = ['david bowie', 'louis armstrong', 'leonard cohen', 'bob dylan','cocteau twins']
x=[1,2,3,4,5]
d=dict(zip(name_list,x))
l=sorted(d.keys())
n = 1
for name in l:
print(f'{n}. {name.title()}')
n+=1

实验2练习


任务五
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))
print("空格数:",test.count(' '))

test = test.replace(',', ' ')
test = test.strip()
test=test.replace("n"," ")
test=test.replace("--"," ")
word = test.split()
word.extend(word)
s=len(word)
print(f"单词数:{s}")
print(word)

实验2练习


任务六
x=[]
s="我的愿望清单"
n=1
while n<4:
s1=input("输入想要加入愿望清单的事情:")
s2=input("输入想要加入愿望清单的事情:")
s3=input("输入想要加入愿望清单的事情:")
n=n+3
x.append(s1)
x.append(s2)
x.append(s3)
print(f"{s:-^50}")
number=0
for i in x:
number+=1
print(f"{number}.",i)

实验2练习

实验总结 
从第四个的字典序的排列,第五个单词数的统计 都用到了很多课外需要自己去了解的知识,也确实只有在实践中才能更多的学习和了解以及使用python

  


程序员灯塔
转载请注明原文链接:实验2练习
喜欢 (0)