实验二

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))

def main():
    pass
if __name__ == '__main__':
    main()
    a = input('输入所需的字符:')

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

a =input('一串字符')
print(len(a.split()))
print(len(a.splitlines()))
print(a.count(' '))

x1=input('愿望一')
x2=input('愿望二')
x3=input('愿望三')
print('{:-^50}'.format('我的愿望清单'))
print('x1')
print('x2')
print('x3')

posted @ 2021-04-08 22:58  麦科勒姆呐  阅读(46)  评论(2编辑  收藏  举报