Huhujingjing commited on
Commit
462f856
·
verified ·
1 Parent(s): f74d5d2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +66 -67
app.py CHANGED
@@ -4,89 +4,88 @@ import pandas as pd
4
  import math
5
 
6
  def add_variables(M, L1, L2, LS, A, z, n):
7
- result = M + L1 + L2 + LS + A + z + n
8
- results = None
9
- r_m = []
10
- r_l1 = []
11
- r_l2 = []
12
- r_ls = []
13
 
14
- if L2 == 0:
15
- if LS == 0:
16
- raise Exception('Error! L2 and LS cannot be both 0, please input again!')
17
- else:
18
- for m in range(math.ceil(2*A / M) + 1):
19
- for l1 in range(math.ceil(2*A / L1) + 1):
20
- for ls in range(math.ceil(2*A / LS) + 1):
21
- total_mass = M * m + L1 * l1 + LS * ls
22
- if (z * A - n <= total_mass <= z * A + n) and ls < m:
23
- r_m.append(m)
24
- r_l1.append(l1)
25
- r_l2.append(None)
26
- r_ls.append(ls)
27
 
28
- results = {
29
  'M': r_m,
30
  'L1': r_l1,
31
  'L2': r_l2,
32
  'LS': r_ls,
33
- }
34
- df = pd.DataFrame(results)
35
- print("符合 {} =< {}*m+{}*l1+{}*ls <= {} 并 LS < M 的所有自然数解有{}组,分别为:"
36
  .format(A - n, M, L1, LS, A + n, len(r_m)))
37
 
38
- print(df.to_markdown(tablefmt="grid"))
39
- df.to_csv("result.csv", index=False)
40
-
41
- else:
42
- if LS == 0:
43
- for m in range(math.ceil(2*A / M) + 1):
44
- for l1 in range(math.ceil(2*A / L1) + 1):
45
- for l2 in range(math.ceil(2*A / L2) + 1):
46
- total_mass = M * m + L1 * l1 + L2 * l2
47
- if z * A - n <= total_mass <= z * A + n:
48
- r_m.append(m)
49
- r_l1.append(l1)
50
- r_l2.append(l2)
51
- r_ls.append(None)
52
-
53
- results = {
54
- 'M': r_m,
55
- 'L1': r_l1,
56
- 'L2': r_l2,
57
- 'LS': r_ls,
58
- }
59
- df = pd.DataFrame(results)
60
- print("符合 {} =< {}*m+{}*l1+{}*l2 <= {} 的所有自然数解有{}组,分别为:"
61
- .format(A - n, M, L1, L2, A + n, len(r_m)))
62
-
63
- print(df.to_markdown(tablefmt="grid"))
64
- df.to_csv("result.csv", index=False)
65
 
66
  else:
67
- for m in range(math.ceil(2*A / M) + 1):
68
- for l1 in range(math.ceil(2*A / L1) + 1):
69
- for l2 in range(math.ceil(2*A / L2) + 1):
70
- for ls in range(math.ceil(2*A / LS) + 1):
71
- total_mass = M * m + L1 * l1 + L2 * l2 + LS * ls
72
- if (z * A - n <= total_mass <= z * A + n) and ls < m:
73
  r_m.append(m)
74
  r_l1.append(l1)
75
  r_l2.append(l2)
76
- r_ls.append(ls)
77
 
78
- results = {
79
- 'M': r_m,
80
- 'L1': r_l1,
81
- 'L2': r_l2,
82
- 'LS': r_ls,
83
- }
84
- df = pd.DataFrame(results)
85
- print("符合 {} =< {}*m+{}*l1+{}*l2+{}*ls <= {} 并 LS < M 的所有自然数解有{}组,分别为:"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
  .format(A - n, M, L1, L2, LS, A + n, len(r_m)))
87
 
88
- print(df.to_markdown(tablefmt="grid"))
89
- df.to_csv("result.csv", index=False)
90
  return df
91
 
92
  iface = gr.Interface(
 
4
  import math
5
 
6
  def add_variables(M, L1, L2, LS, A, z, n):
7
+
8
+ r_m = []
9
+ r_l1 = []
10
+ r_l2 = []
11
+ r_ls = []
 
12
 
13
+ if L2 == 0:
14
+ if LS == 0:
15
+ raise Exception('Error! L2 and LS cannot be both 0, please input again!')
16
+ else:
17
+ for m in range(math.ceil(2*A / M) + 1):
18
+ for l1 in range(math.ceil(2*A / L1) + 1):
19
+ for ls in range(math.ceil(2*A / LS) + 1):
20
+ total_mass = M * m + L1 * l1 + LS * ls
21
+ if (z * A - n <= total_mass <= z * A + n) and ls < m:
22
+ r_m.append(m)
23
+ r_l1.append(l1)
24
+ r_l2.append(None)
25
+ r_ls.append(ls)
26
 
27
+ results = {
28
  'M': r_m,
29
  'L1': r_l1,
30
  'L2': r_l2,
31
  'LS': r_ls,
32
+ }
33
+ df = pd.DataFrame(results)
34
+ print("符合 {} =< {}*m+{}*l1+{}*ls <= {} 并 LS < M 的所有自然数解有{}组,分别为:"
35
  .format(A - n, M, L1, LS, A + n, len(r_m)))
36
 
37
+ print(df.to_markdown(tablefmt="grid"))
38
+ df.to_csv("result.csv", index=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
 
40
  else:
41
+ if LS == 0:
42
+ for m in range(math.ceil(2*A / M) + 1):
43
+ for l1 in range(math.ceil(2*A / L1) + 1):
44
+ for l2 in range(math.ceil(2*A / L2) + 1):
45
+ total_mass = M * m + L1 * l1 + L2 * l2
46
+ if z * A - n <= total_mass <= z * A + n:
47
  r_m.append(m)
48
  r_l1.append(l1)
49
  r_l2.append(l2)
50
+ r_ls.append(None)
51
 
52
+ results = {
53
+ 'M': r_m,
54
+ 'L1': r_l1,
55
+ 'L2': r_l2,
56
+ 'LS': r_ls,
57
+ }
58
+ df = pd.DataFrame(results)
59
+ print("符合 {} =< {}*m+{}*l1+{}*l2 <= {} 的所有自然数解有{}组,分别为:"
60
+ .format(A - n, M, L1, L2, A + n, len(r_m)))
61
+
62
+ print(df.to_markdown(tablefmt="grid"))
63
+ df.to_csv("result.csv", index=False)
64
+
65
+ else:
66
+ for m in range(math.ceil(2*A / M) + 1):
67
+ for l1 in range(math.ceil(2*A / L1) + 1):
68
+ for l2 in range(math.ceil(2*A / L2) + 1):
69
+ for ls in range(math.ceil(2*A / LS) + 1):
70
+ total_mass = M * m + L1 * l1 + L2 * l2 + LS * ls
71
+ if (z * A - n <= total_mass <= z * A + n) and ls < m:
72
+ r_m.append(m)
73
+ r_l1.append(l1)
74
+ r_l2.append(l2)
75
+ r_ls.append(ls)
76
+
77
+ results = {
78
+ 'M': r_m,
79
+ 'L1': r_l1,
80
+ 'L2': r_l2,
81
+ 'LS': r_ls,
82
+ }
83
+ df = pd.DataFrame(results)
84
+ print("符合 {} =< {}*m+{}*l1+{}*l2+{}*ls <= {} 并 LS < M 的所有自然数解有{}组,分别为:"
85
  .format(A - n, M, L1, L2, LS, A + n, len(r_m)))
86
 
87
+ print(df.to_markdown(tablefmt="grid"))
88
+ df.to_csv("result.csv", index=False)
89
  return df
90
 
91
  iface = gr.Interface(