Skip to content

Commit 119bb6f

Browse files
authored
Add files via upload
1 parent 7a74d5d commit 119bb6f

File tree

1 file changed

+56
-16
lines changed

1 file changed

+56
-16
lines changed

youngModulus.py

Lines changed: 56 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,48 @@
22
# 图形界面待开发
33

44
import math
5+
import openpyxl as opx
56

67
p = math.pi
78

89

9-
def main():
10+
def get_by_io():
11+
# 对标尺数据的处理
12+
# 获取最基本的xi+和xi-的数据
13+
a = input('请输入xi+的九个值,单位mm,每个值之间用空格隔开,不要有其他额外输入').split()
14+
b = input('请输入xi-的九个值,单位mm,每个值之间用空格隔开,不要有其他额外输入').split()
15+
16+
# 对直径数据的处理
17+
# 获取最基本的d的数据
18+
c = input('请输入0.00kg时测得的三个钢丝直径的数据,单位mm,各数据间用空格隔开,不要有其他额外输入').split()
19+
d = input('请输入9.00kg时测得的三个钢丝直径的数据,单位mm,各数据间用空格隔开,不要有其他额外输入').split()
20+
return a, b, c, d
21+
22+
23+
def get_by_xlsx():
24+
workbook = opx.load_workbook('./1.xlsx')
25+
sheet = workbook.active
26+
a = []
27+
b = []
28+
c = []
29+
d = []
30+
for i in sheet.iter_rows(min_row=2, max_row=2, min_col=1, max_col=10):
31+
for k in i:
32+
a.append(k.value)
33+
for i in sheet.iter_rows(min_row=4, max_row=4, min_col=1, max_col=10):
34+
for k in i:
35+
b.append(k.value)
36+
for i in sheet.iter_rows(min_row=6, max_row=6, min_col=1, max_col=3):
37+
for k in i:
38+
c.append(k.value)
39+
for i in sheet.iter_rows(min_row=8, max_row=8, min_col=1, max_col=3):
40+
for k in i:
41+
d.append(k.value)
42+
print(a, b, c, d)
43+
return a, b, c, d
44+
45+
46+
def main(xiPlus, xiMinus, d_0, d_9):
1047
# 以下是我自己测得的实验数据
1148
# xiPlus = [6.1, 9.2, 12.1, 15.2, 18.6, 21.4, 24.3, 27.8, 30.3, 33.8]
1249
# xiMinus = [5.2, 8.7, 12.0, 14.9, 17.8, 20.9, 24.0, 27.2, 30.7, 33.0]
@@ -15,10 +52,7 @@ def main():
1552
# L = 738
1653
# H = 812
1754
# b = 501
18-
# 对标尺数据的处理
19-
# 获取最基本的xi+和xi-的数据
20-
xiPlus = input('请输入xi+的九个值,单位mm,每个值之间用空格隔开,不要有其他额外输入').split()
21-
xiMinus = input('请输入xi-的九个值,单位mm,每个值之间用空格隔开,不要有其他额外输入').split()
55+
2256
xi = []
2357
for i in range(len(xiPlus)):
2458
xi.append((float(xiPlus[i]) + float(xiMinus[i])) / 2)
@@ -38,11 +72,6 @@ def main():
3872
AD_xi = AD_xi + abs(y - average_delta_xi)
3973
AD_xi = AD_xi / 5
4074

41-
# 对直径数据的处理
42-
# 获取最基本的d的数据
43-
d_0 = input('请输入0.00kg时测得的三个钢丝直径的数据,单位mm,各数据间用空格隔开,不要有其他额外输入').split()
44-
d_9 = input('请输入9.00kg时测得的三个钢丝直径的数据,单位mm,各数据间用空格隔开,不要有其他额外输入').split()
45-
4675
# 对数据进行进一步处理
4776
average_d = [] # 对上中下三个尺寸取均值
4877
for i in range(len(d_0)):
@@ -85,9 +114,20 @@ def main():
85114

86115

87116
if __name__ == '__main__':
88-
print('===============================================')
89-
print('测定金属杨氏模量实验的数据处理脚本,一站式解决所有计算')
90-
print('\t\t\tmade by zzx')
91-
print('you can also find the code at the following URL:')
92-
print('https://github.com/coder-Zzx/experiment_project.git')
93-
main()
117+
print('=======================================================')
118+
print('| 测定金属杨氏模量实验的数据处理脚本,一站式解决所有计算 |')
119+
print('| made by zzx |')
120+
print('---------------------------------------version 1.2-----')
121+
print('| you can also find the code at the following URL: |')
122+
print('| https://github.com/coder-Zzx/experiment_project.git |')
123+
print('=======================================================', end='\n\n')
124+
print('=======================================================')
125+
print('| 1.从键盘输入 |')
126+
print('| 2.从Excel文件输入 |')
127+
ans = input('|\t请选择输入模式\t|')
128+
if ans == '1':
129+
xiPlus, xiMinus, d_0, d_9 = get_by_io()
130+
if ans == '2':
131+
print('请在代码相同路径下的1.xlsx工作表内按格式输入实验数据.')
132+
xiPlus, xiMinus, d_0, d_9 = get_by_xlsx()
133+
main(xiPlus=xiPlus, xiMinus=xiMinus, d_0=d_0, d_9=d_9)

0 commit comments

Comments
 (0)