实验二

x1,y1=1.2,3.57
x2,y2=2.26,8.7
# 输出1
print('{:-^40}'.format('输出1'))
# 这样可以输出-分割线,输出1字符居中
print('x1={},y1={}'.format(x1,y1))
print('x2={},y2={}'.format(x2,y2))
# 我还是喜欢新版本的写法。
# 输出2
print('{:-^40}'.format('输出2'))
print('x1={:.1f},y1={:.1f}'.format(x1,y1))
print('x2={:.1f},y2={:.1f}'.format(x2,y2))
# {:.xf}可以控制输出精度到x位
# 输出3
print('{:-^40}'.format('输出3'))
print('x1 = {:<15}, y1 = {:<15}'.format(x1, y1)) 
print('x2 = {:<15}, y2 = {:<15}'.format(x2, y2))
# {:<15控制输出15字符的长度}

     task2
s=input("输入一段英文:")
print(s.upper().replace("A",""))
name_list=["work hard","a loving","beautiful girl","and the","thanks them"]
n=1
for name in name_list:
    print(f"{n}:{name.title()}")
n+=1
name_list = ['a girl', 'likes flowers', 'leonard cohen', 'bob dylan', 'cocteau twins']
name_list = sorted(name_list)
n=1
for name in name_list:
    print(f'{n}.{name.title()}')
str1=input("请输入任意字符串")
list1=[]
list2=[]
for i in str1:
   if i.isdigit()==True:
      list2.append(int(i))
   else:
        list1.append(i.upper())
print(list2)
print(list1)



x = '''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!
'''
a = len(x.splitlines())
b = len(x.split())
c = len(x)
d = 0
for str in x:
    if str == ' ':
        d += 1
print('行数:',a)
print('单词数:',b)
print('字符数:',c)
print('空格数:',d)

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


 


 

 

 

 

  

 


  

posted @ 2021-04-18 10:41  麦热姆  阅读(51)  评论(0)    收藏  举报