实验1 python开发环境使用和编程初体验
1 print('hey, u') 2 3 print('hey', ' u') 4 x,y,z = 1,2,3 5 print(x, y, z) 6 7 print('x = %d, y = %d, z = %d' %(x,y,z)) 8 print('x = {}, y = {}, z = {}'.format(x,y,z)) 9 print(f'x = {x}, y = {y}, z = {z}') 10 11 print(x) 12 print(y) 13 print(z) 14 15 print(x, end=' ') 16 print(y, end=' ') 17 print(z,end=' ')
运行结果:

实验任务2
x1, y1 = 1.2, 3.57 x2, y2 = 2.26, 8.7 print('{:-^40}'.format('输出1')) print('x1 = {}, y1 = {}'.format(x1, y1)) print('x2 = {}, y2 = {}'.format(x2, y2)) print('{:-^40}'.format('输出2')) print('x1 = {:.1f}, y1 = {:.1f}'.format(x1, y1)) print('x2 = {:.1f}, y2 = {:.1f}'.format(x2, y2)) print('{:-^40}'.format('输出3')) print('x1 = {:<15.1f}, y1 = {:<15.1f}'.format(x1, y1)) print('x2 = {:<15.1f}, y2 = {:<15.1f}'.format(x2, y2)) print('{:-^40}'.format('输出4')) print('x1 = {:>15.1f}, y1 = {:>15.1f}'.format(x1, y1)) print('x2 = {:>15.1f}, y2 = {:>15.1f}'.format(x2, y2))
运行结果

实验任务3
name1, age1 = 'Bill', 19
name2, age2 = 'Hellen', 18
title = 'Personnel Information'
print(f'{title:=^40}')
print(f'name: {name1:10} age: {age1:3}')
print(f'name: {name2:10} age: {age2:3}')
print(40*'=')
运行结果3

浙公网安备 33010602011771号