4-python作业整活(代码分享)
这次作业懒得整活,简化了一下代码下载,新增
Release
板块可以直接下载打包后的文件.
*Download
板块可能会在以后版本移除.
Download
- example3_1.py
- question3_1.py
- example3_2.py
- example3_3.py
- example3_4.py
- example3_5.py
- exercise4_1.py
- exercise4_2.py
- exercise4_3.py
Release
- Setup
- 安装包下载的文件默认在桌面上,后续学习后有望提供更灵活的自定义安装,现在我还不会.
提交作业
example3_1.py
1
2
3
4
5
6
7
8
9
10
11# example3_1.py
# coding=utf-8
import math
r = eval(input("请输入圆的半径:"))
if r >= 0:
d = 2 * math.pi * r
s = math.pi * r ** 2
print('圆的周长=', d, '圆的面积=', s)question3_1.py
1
2
3
4
5
6
7
8
9
10
11# question3_1.py
# coding=utf-8
import math
r = eval(input("请输入圆的半径:"))
if r >= 0:
d = 2 * math.pi * r
s = math.pi * r ** 2
print('圆的周长=', d, '圆的面积=', s)example3_2.py
1
2
3
4
5
6
7
8
9# example3_2.py
# coding=utf-8
t = int(input("请输入年份:"))
if t % 400 == 0 or (t % 4 == 0 and t % 100 != 0):
print(t, '年是闰年', sep='')
else:
print(t, '年不是闰年', sep='')example3_3.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15# example3_3.py
# coding=utf-8
jobSeeker_info = {
'age':24,
'major':'投资银行',
'if_key':'false',
'exp':3,
}
def in_notice(info):#Interview Notice
if info['age']<=25 and info['major']=='金融工程' and info['if_key']=='true' or info['major']=='投资银行' and info['exp']>=3:
print('面试通知')
in_notice(jobSeeker_info)example3_4.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23# example3_4.py
# coding=utf-8
price = eval(input("请输入标准价格:"))
Quantity = eval(input("请输入订货量:"))
if Quantity < 0 or price < 0:
print("输入的订货量与标准价格均不能小于0!")
else:
if Quantity < 300:
Coff = 0.0
elif Quantity < 500:
Coff = 0.03
elif Quantity < 1000:
Coff = 0.05
elif Quantity < 2000:
Coff = 0.08
else:
Coff = 0.1
print("折扣率为:", Coff)
Pays = Quantity * price * (1 - Coff)
print("支付金额:", Pays)example3_5.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27# example3_5.py
# coding=utf-8
Ctype = int(input("请输入客户类型(小于5为新客户):"))
Price = eval(input("请输入标准价格:"))
Quantity = eval(input("请输入订货数量:"))
if Ctype > 0 and Price > 0 and Quantity > 0:
if Ctype < 5:
if Quantity < 800:
Coff = 0
else:
Coff = 0.02
else:
if Quantity < 500:
Coff = 0.03
elif Quantity < 1000:
Coff = 0.05
elif Quantity < 2000:
Coff = 0.08
else:
Coff = 0.1
Pays = Quantity * Price * (1 - Coff)
print("应付款为:", Pays)
else:
print("输入错误。")exercise4_1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15# exercise4_1.py
# coding=utf-8
score = int(input("请输入百分制成绩(0\~100):"))
if score >= 90:
print('A')
elif score >= 80:
print('B')
elif score >= 70:
print('C')
elif score >= 60:
print('D')
else:
print('E')exercise4_2.py
1
2
3
4
5
6
7
8
9# exercise4_2.py
# coding=utf-8
r = 177777777802222222005
if r % 18 == 0 or (r + 15) % 18 == 0:
print(r, '是符合要求的数字', sep='')
else:
print(r, '不是符合要求的数字', sep='')exercise4_3.py
1
2
3
4
5
6
7
8
9
10# exercise4_3.py
# coding=utf-8
import math
a = 8
b = 18
sita = 45
c = math.sqrt(a**2+b**2-2*a*b*math.cos(math.radians(sita)))
print(f'第三边长度为{c}')