Created
October 2, 2019 07:26
-
-
Save renyuanL/25317bbfbd840a22bbd7a92657c7a333 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
ryPythonHk002.py | |
解二元一次方程式002 | |
''' | |
aMessage= ''' | |
solve: | |
a x + b y = c | |
d x + e y = f | |
input: | |
a,b,c | |
d,e,f | |
solution: | |
x= ? | |
y= ? | |
''' | |
print(aMessage) | |
def f1_input(): | |
a= float(input('a=? ')) | |
b= float(input('b=? ')) | |
c= float(input('c=? ')) | |
d= float(input('d=? ')) | |
e= float(input('e=? ')) | |
f= float(input('f=? ')) | |
return a,b,c,d,e,f | |
a,b,c,d,e,f = f1_input() | |
def f2_solve(a,b,c,d,e,f): | |
delta= a*e-d*b | |
deltaX= c*e-f*b | |
deltaY= a*f-d*c | |
x= deltaX/delta | |
y= deltaY/delta | |
return x,y | |
x,y = f2_solve(a,b,c,d,e,f) | |
print('the solution is ...') | |
print('x= ', x) | |
print('y= ', y) | |
# 驗算.... | |
def f3_驗算(a,b,c,d,e,f,x,y): | |
p1= (a*x+b*y == c) | |
p2= (d*x+e*y == f) | |
p= p1 and p2 | |
return p | |
p = f3_驗算(a,b,c,d,e,f,x,y) | |
print('驗算....') | |
print('p= ', p) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment