实验二
# 使用字符串的format()方法,对输出数据项进行格式化
x1, y1 = 1.2, 3.57
x2, y2 = 2.26, 8.7
# 输出1
print('{:-^40}'.format('输出1')) # {:-^40}控制输出数据格式: 宽度占40列,居中对
齐,空白处用-补齐
print('x1 = {}, y1 = {}'.format(x1, y1))
print('x2 = {}, y2 = {}'.format(x2, y2))
# 输出2
print('{:-^40}'.format('输出2')) # {:-^40}控制输出数据格式: 宽度占40列,居中对
齐,空白处用-补齐
print('x1 = {:.1f}, y1 = {:.1f}'.format(x1, y1)) # {:.1f}控制小数输出精度,保留
1位小数
print('x2 = {:.1f}, y2 = {:.1f}'.format(x2, y2))
# 输出3
print('{:-^40}'.format('输出3')) # {:-^40} 控制输出数据格式: 宽度占40列,居中对
齐,空白处用-补齐
print('x1 = {:<15}, y1 = {:<15}'.format(x1, y1)) # {:<15}控制数据输出宽度占15
列,左对齐,空白处默认补空格
print('x2 = {:<15}, y2 = {:<15}'.format(x2, y2))

x = input('输入字符串')
x = x.upper()
x = x.replace('A','')
print(x)

# 把姓名转换成大写,遍历输出
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

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

x = 'Zen Of Python'
print(len(x.splitlines()))
print(len(x.split()))
print(len(x))
print(x.count(''))

x = list({})
for n in range(3):
m = input('输入想要加入愿望清单的事情: ')
x.append(m)
print('{:-^50}'.format('我的愿望清单'))
for n in range(1,4):
print(n,end='')
print("."+x[n-1])

实验总结
1.就是打了一些代码后有悟到一些工具的用法
2.学这个还是要多背多记才方便使用
浙公网安备 33010602011771号