- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMathbox.py
More file actions
Latest commit
49 lines (40 loc) · 1.45 KB
/
Copy pathMathbox.py
File metadata and controls
49 lines (40 loc) · 1.45 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/user/bin/python
importmath
deflef(x): # 用于计算出方程左边的值,函数righ同理
l=x*x-13/4
returnl
defrigh(x):
r=math.sqrt(5)*x
returnr
defjudge(a, b, c, d, e): # 用于判断是否是方程的解
x= (a*math.sqrt(b) +c*math.sqrt(d)) /e
left=lef(x)
right=righ(x)
ifabs(left-right) <0.000000001:
print("x=(", a, "*√", b, "+", c, "*√", d, ")/", e)
return1
else:
return0
defmathbox(m,n): # 函数主体,m、n用于限制循环范围
forain [xforxinrange(m+1)]:
forbin [x+1forxinrange(n)]:
forein [x+1forxinrange(m)]:
forcin [xforxinrange(m+1)]:
fordin [x+1forxinrange(n)]:
answer=0
answer=judge(a, b, c, d, e)
ifanswer==1:
return
c=0-c
answer=judge(a, b, c, d, e)
ifanswer==1:
return
a=0-a; c=0-c
answer=judge(a, b, c, d, e)
ifanswer==1:
return
c=0-c
answer=judge(a, b, c, d, e)
ifanswer==1:
return
mathbox(20, 20)