实验任务1

x = list(range(10))
print('整数输出1: ', end = '')

for i in x:
    print(f'{i:02d}', end = '-')

print('\n整数输出3: ', end = '')
for i in x[:-1]:
    print(f'{i:02d}', end = '-')
print(f'{x[-1]:02d}')

print('\n字符输出1: ', end = '')
y1 = [str(i) for i in range(10)]
print('-'.join(y1))

实验任务2

name_list = ['david bowie', 'louis armstrong', 'leonard cohen', 'bob dylan', 'cocteau twins']
3 for name in name_list:
4     print(name.title())
5 print()
6 
7 name_list_captilize=[name.title() for name in name_list]
8 print('\n'.join(name_list_captilize))

实验任务3

name_list = ['david bowie', 'louis armstrong', 'leonard cohen', 'bob dylan', 'cocteau twins']
name_list_captilize=[name.title() for name in name_list]
list3=sorted(name_list_captilize)
for id,name in enumerate(list3):
    print('{}.'.format(id+1),name)

实验任务4

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!'''
linenum=0
letternum=0
strinum=0
spacenum=0
linenum=text.count('\n')+1
print(f'行数是:{linenum}')
for i in text:
    if i==' ':
        spacenum+=1
print(f'单词数是:{len(text.split())}')
print(f'字符数是:{len(text)}')
print(f'空格数是:{spacenum}')

实验任务5

book_list = [['静静的顿河','肖洛霍夫','金人', '人民文学出版社'],
['大地之上','罗欣顿.米斯特里','张亦琦', '天地出版社'],
['夜航西飞', '柏瑞尔.马卡姆', '陶立夏', '人民文学出版社'],
['来自民间的叛逆', '袁越', '','新星出版社'],
['科技与恶的距离', '珍妮.克里曼', ' 詹蕎語', '墨刻出版社'],
['灯塔','克里斯多夫.夏布特','吕俊君','北京联合出版公司'],
['小行星掉在下午','沈大成', '', '广西师范大学出版社']]
for index,book in enumerate(book_list):
    print(f'{index+1}.《{book[0]}》|{book[1]}|{book[3]}')

总结:灵活使用index函数来排序即对应的是for index,x in enumerate()

实验任务6

data = ['99 81 75', '30 42 90 87', '69 50 96 77 89 93', '82 99 78 100']
n=0
num=0
for i in data:
    b=i.split()
    for j in b:
        n=n+int(j)
        num+=1
    a=n/num
print('{:.2f}'.format(a))

总结:回忆了关于保留小数、精度的问题

实验任务7

words_sensitive_list = ['张三', 'V字仇杀队', '']
comments_list = ['张三因生命受到威胁正当防卫导致过失杀人,经辩护律师努力,张三不需负刑事 责任。',
                 '电影<V字仇杀队>从豆瓣下架了',
                 '娱乐至死']
c = '\n'.join(comments_list)
for sensitive_word in words_sensitive_list:
    a=sensitive_word.rstrip()
    if a in c:
        b=len(a)
        c=c.replace(a,'*'*b)
else:
         print(c)

实验2总结:从这次实验总结中我复习了字符串和列表的一些操作和对一些函数的运用,掌握了取小数的方法以及替代关键字,虽然依旧不够熟练,但我会继续努力。