实验1 python开发环境使用和编程初体验

print('hey', ' u')
x,y,z = 1,2,3
print(x, y, z)

print('x = %d, y = %d, z = %d' %(x,y,z)) # 方式1: 传统c风格
print('x = {}, y = {}, z = {}'.format(x,y,z)) # 方式2: s.format()方法
print(f'x = {x}, y = {y}, z = {z}') # 方式3: f-string方式

print(x) 
print(y)
print(z)
print(x, end=' ') 
print(y, end=' ')
print(z)

实验结果截图:

实验任务1-2:

 1 x1, y1 = 1.2, 3.57
 2 x2, y2 = 2.26, 8.7
 3 print('{:-^40}'.format('输出1'))
 4 print('x1 = {}, y1 = {}'.format(x1, y1))
 5 print('x2 = {}, y2 = {}'.format(x2, y2))
 6 print('{:-^40}'.format('输出2'))
 7 print('x1 = {:.1f}, y1 = {:.1f}'.format(x1, y1))
 8 print('x2 = {:.1f}, y2 = {:.1f}'.format(x2, y2))
 9 print('{:-^40}'.format('输出3'))
10 print('x1 = {:<15.1f}, y1 = {:<15.1f}'.format(x1, y1))
11 print('x2 = {:<15.1f}, y2 = {:<15.1f}'.format(x2, y2))

实验结果截图:

 

实验任务1-3:

1 name1, age1 = 'Bill', 19
2 name2, age2 = 'Hellen', 18
3 title = 'Personnel Information'
4 print(f'{title:=^40}')
5 print(f'name: {name1:10} age: {age1:3}')
6 print(f'name: {name2:10} age: {age2:3}')
7 print(40*'=')

实验结果截图:

 实验任务2-1:

1 r1 = eval('1 + 2') 
2 print(type(r1), r1)
3 r2 = eval('1+2j') 
4 print(type(r2), r2)
5 r3 = eval('"python"') 
6 print(type(r3), r3)
7 r4 = eval('7, 42') 
8 print(type(r4), r4)

截图:

实验任务2-2:

1 x, y = eval(input('Enter two oprands: ')) 
2 ans = x + y
3 print(f'{x} + {y} = {ans}')
4 print(f'{type(x)} + {type(y)} = {type(ans)}')

截图:

实验任务3:

1 ans1 = 0.1 + 0.2
2 print(f'0.1 + 0.2 = {ans1}')
3 import decimal
4 ans2 = decimal.Decimal('0.1') + decimal.Decimal('0.2')
5 print(f'0.1 + 0.2 = {ans2}')

截图:

实验任务4:

 1 print(chr(0x1f600), end = " ")
 2 print(chr(0x1f601), end = " ")
 3 print(chr(0x1f602), end = " ")
 4 print(chr(0x1f603), end = " ")
 5 print(chr(0x1f604))
 6 print(chr(10000), end=" ")
 7 print(chr(0x025b), end=" ")
 8 print(chr(0x2708), end=" ")
 9 print(chr(0x00A5), end=" ")
10 print(chr(0x266b))
11 print(ord('a'), end = " ")
12 print(ord('b'), end = " ")
13 print(ord('c'))
14 print(ord('A'), end = " ")
15 print(ord('B'), end = " ")
16 print(ord('C'))
17 print(ord('0'), end = " ")
18 print(ord('1'), end = " ")
19 print(ord('2'))

截图:

实验任务5-1:

1 import math
2 n = float(input('输入一个数:'))
3 # python中计算开平方的三种方式
4 ans1 = n**0.5
5 ans2 = pow(n, 0.5)
6 ans3 = math.sqrt(n)
7 print('%.2f的平方根是: %.2f' %(n, ans1)) 
8 print('{:.2f}的平方根是: {:.2f}'.format(n, ans2)) 
9 print(f'{n:.2f}的平方根是: {ans3:.2f}') 

截图:

实验任务5-2:

 1 import math
 2 text = '''
 3 好奇心是人的天性。
 4 理想情况下,学习新东西是让人愉快的事。
 5 但学校里的学习似乎有点像苦役。
 6 有时候,需要画一个大饼,每次尝试学一些新鲜的,才会每天变得更好一点点。
 7 '''
 8 print(text)
 9 r = float(input('给学习画一个大饼,大饼要做的很大,半径要这么大: '))
10 circle = 2*math.pi*r
11 print(f'绕起来,大饼的圆周有这么长, {circle}, 够不够激发你探索未知的动力...')

截图:

 实验任务6:

1 x=float(input())
2  y=x**365
3  print(f'{x}的365次方:{y}')

截图:

实验任务7:

 1 import math
 2 p = 1.038
 3 c = 3.7
 4 K = 0.0054
 5 Tw = 100
 6 Ty = 70
 7 T0 = int(input('enter your temperture'))
 8 M = 67
 9 
10 x1=M**(2/3)*c*p**(1/3)
11 x2=(0.76 * (T0 - Tw) / (Ty - Tw))
12 a=math.pi
13 x3=K*a**2*(4*a/3)**(2/3)
14 x4=math.log(x2)
15 t=x1/x3*x4
16 min = t // 60
17 sec = t % 60
18 
19 print(f'T0 = {T0:.2f}℃',f't={min:.2f}分{sec:.2f}秒')

截图:

实验任务8-1:

 1 """
 2 家用电器销售系统
 3 V1.0
 4 """
 5 
 6 #欢迎信息
 7 print('欢迎使用家用电器销售系统!')
 8 
 9 #产品信息列表
10 print('产品和价格信息如下:')
11 print('*********************************************************')
12 print('%-10s'%'编号','%-10s'%'名称','%-10s'%'品牌','%-10s'%'价格','%-10s'%'库存数量')
13 print('---------------------------------------------------------------------')
14 print('%-10s'%'0001','%-10s'%'电视机','%-10s'%'海尔','%-10.2f'%5999.00,'%10d'%20)
15 print('%-10s'%'0002','%-10s'%'冰箱','%-10s'%'西门子','%-10.2f'%6998.00,'%10d'%15)
16 print('%-10s'%'0003','%-10s'%'洗衣机','%-10s'%'小天鹅','%-10.2f'%1999.00,'%10d'%10)
17 print('%-10s'%'0004','%-10s'%'空调','%-10s'%'格力','%-10.2f'%3900.00,'%10d'%0)
18 print('%-10s'%'0005','%-10s'%'热水器','%-10s'%'美的','%-10.2f'%688.00,'%10d'%30)
19 print('%-10s'%'0006','%-10s'%'笔记本','%-10s'%'联想','%-10.2f'%5699.00,'%10d'%10)
20 print('%-10s'%'0007','%-10s'%'微波炉','%-10s'%'苏泊尔','%-10.2f'%480.00,'%10d'%33)
21 print('%-10s'%'0008','%-10s'%'投影仪','%-10s'%'松下','%-10.2f'%1250.00,'%10d'%12)
22 print('%-10s'%'0009','%-10s'%'吸尘器','%-10s'%'飞利浦','%-10.2f'%999.00,'%10d'%9)
23 print('-----------------------------------------------------------------------')
24 
25 #用户输人信息
26 prodect_id=input('请输入您要购买的产品编号:')
27 price=float(input('请输入您要购买的产品价格:'))
28 count=int(input('请输入您要购买的产品数量:'))
29 
30 #计算金额
31 print('购买成功,您需要支付',price * count,'')
复制代码

截图:

实验任务8-2:

1 """
 2 家用电器销售系统
 3 V1.0
 4 """
 5 
 6 #欢迎信息
 7 print('欢迎使用家用电器销售系统!')
 8 
 9 #产品信息列表
10 print('产品和价格信息如下:')
11 print('*********************************************************')
12 print('{:<10}'.format('编号'),'{:<10}'.format('名称'),'{:<10}'.format('品牌'),'{:<10}'.format('价格'),'{:<10}'.format('库存数量'))
13 print('---------------------------------------------------------------------')
14 print('{:<10}'.format('0001'),'{:<10}'.format('电视机'),'{:<10}'.format('海尔'),'{:<10.2f}'.format(5999.00),'{:>10}'.format(20))
15 print('{:<10}'.format('0002'),'{:<10}'.format('冰箱'),'{:<10}'.format('西门子'),'{:<10.2f}'.format(6998.00),'{:>10}'.format(15))
16 print('{:<10}'.format('0003'),'{:<10}'.format('洗衣机'),'{:<10}'.format('小天鹅'),'{:<10.2f}'.format(1999.00),'{:>10}'.format(10))
17 print('{:<10}'.format('0004'),'{:<10}'.format('空调'),'{:<10}'.format('格力'),'{:<10.2f}'.format(3900.00),'{:>10}'.format(0))
18 print('{:<10}'.format('0005'),'{:<10}'.format('热水器'),'{:<10}'.format('美的'),'{:<10.2f}'.format(688.00),'{:>10}'.format(30))
19 print('{:<10}'.format('0006'),'{:<10}'.format('笔记本'),'{:<10}'.format('联想'),'{:<10.2f}'.format(5699.00),'{:>10}'.format(10))
20 print('{:<10}'.format('0007'),'{:<10}'.format('微波炉'),'{:<10}'.format('苏泊尔'),'{:<10.2f}'.format(480.50),'{:>10}'.format(33))
21 print('{:<10}'.format('0008'),'{:<10}'.format('投影仪'),'{:<10}'.format('松下'),'{:<10.2f}'.format(1250.00),'{:>10}'.format(12))
22 print('{:<10}'.format('0009'),'{:<10}'.format('吸尘器'),'{:<10}'.format('飞利浦'),'{:<10.2f}'.format(999.00),'{:>10}'.format(9))
23 print('-----------------------------------------------------------------------')
24 
25 #用户输人信息
26 prodect_id=input('请输入您要购买的产品编号:')
27 price=float(input('请输入您要购买的产品价格:'))
28 count=int(input('请输入您要购买的产品数量:'))
29 
30 #计算金额
31 print('购买成功,您需要支付',price * count,'')
32 
33 #退出系统
34 print("谢谢您的光临,下次再见!")

截图:

实验任务8-3:

1 """
 2 家用电器销售系统
 3 v1.0
 4 """
 5 
 6 bh = '编号'
 7 mc = '名称'
 8 pp = '品牌'
 9 jg = '价格'
10 kcs = '库存数量'
11 x1 = '电视机'
12 x2 ='冰箱'
13 x3 = '洗衣机'
14 x4 = '空调'
15 x5 = '热水器'
16 x6 = '笔记本'
17 x7 = '微波炉'
18 x8 = '投影仪'
19 x9 = '吸尘器'
20 A = '0001'
21 B = '0002'
22 C = '0003'
23 D = '0004'
24 E = '0005'
25 G = '0006'
26 H = '0007'
27 I = '0008'
28 J = '0009'
29 hr = '海尔'
30 xmz = '西门子'
31 xte = '小天鹅'
32 gl = '格力'
33 md = '美的'
34 lx = '联想'
35 sbe = '苏泊尔'
36 sx = '松下'
37 flp = '飞利浦'
38 
39 #欢迎信息
40 print('欢迎使用家用电器销售系统!')
41 #产品信息列表
42 print('产品和价格信息如下:')
43 print('*********************************************************')
44 print('---------------------------------------------------------------------')
45 print(f'{bh:<10}',f'{mc:<10}',f'{pp:<10}',f'{jg:<10}',f'{kcs:>10}')
46 print(f'{A:<10}',f'{x1:<10}',f'{hr:<10}',f'{5999.00:<10.2f}',f'{20:>10}')
47 print(f'{B:<10}',f'{x2:<10}',f'{xmz:<10}',f'{6998.00:<10.2f}',f'{15:>10}')
48 print(f'{C:<10}',f'{x3:<10}',f'{xte:<10}',f'{1999.00:<10.2f}',f'{10:>10}')
49 print(f'{D:<10}',f'{x4:<10}',f'{gl:<10}',f'{3900.00:<10.2f}',f'{0:>10}')
50 print(f'{E:<10}',f'{x5:<10}',f'{md:<10}',f'{688.00:<10.2f}',f'{30:>10}')
51 print(f'{G:<10}',f'{x6:<10}',f'{lx:<10}',f'{5699.00:<10.2f}',f'{10:>10}')
52 print(f'{H:<10}',f'{x7:<10}',f'{sbe:<10}',f'{480.50:<10.2f}',f'{33:>10}')
53 print(f'{I:<10}',f'{x8:<10}',f'{sx:<10}',f'{1250.00:<10.2f}',f'{12:>10}')
54 print(f'{J:<10}',f'{x9:<10}',f'{flp:<10}',f'{999.00:<10.2f}',f'{9:>10}')
55 print('-----------------------------------------------------------------------')
56 
57 #用户输人信息
58 prodect_id=input('请输入您要购买的产品编号:')
59 price=float(input('请输入您要购买的产品价格:'))
60 count=int(input('请输入您要购买的产品数量:'))
61 
62 #计算金额
63 print('购买成功,您需要支付',price * count,'')
64 #退出系统
65 print("谢谢您的光临,下次再见!")

截图:

 

posted @ 2023-03-08 11:32  kuma-ja  阅读(23)  评论(0)    收藏  举报