Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- def gcd(a):
- for i, n in enumerate(a): a[i] = abs(n)
- a.sort()
- min = a[0]
- result = 1
- for i in range(2, min+1):
- flag = True
- for j in a:
- if j % i != 0: flag = False
- if flag == True: result = i
- return result
- def readeqn(eqn,dictn):
- for i in dictn:
- eqn[i] = input(i[0]+'=')
- if eqn['A'] == 0 and eqn['B'] == 0:
- raise TypeError("No Both Zero!")
- def simeqn(eqn,dictn):
- eqn_gcd = gcd(eqn.values())
- for i in dictn:
- eqn[i] = eqn[i]/abs(eqn_gcd)
- def printeqn(eqn,dictn):
- eqn_text = ''
- for i in dictn:
- if eqn[i]>0 and i!='A': eqn_text+= '+'
- eqn_text += str(eqn[i])+dictn[i]
- print eqn_text+'=0'
- def calceqn(eqn,dictn):
- readeqn(eqn,dictn)
- simeqn(eqn,dictn)
- printeqn(eqn,dictn)
- # -- Read eqn1 --
- print 'Type Ax²+By²+C=0:'
- dict1 = {'A':'x', 'B':'y', 'C':''}
- eqn1 = {'A': 0, 'B': 0, 'C': 0}
- calceqn(eqn1,dict1)
- # -- READ eqn2 --
- print 'Type Ax²+By²+Dx+Ey+F=0:'
- dict2 = {'A':'x²', 'B':'y²', 'D':'x', 'E':'y', 'F':''}
- eqn2 = {'A':0, 'B':0, 'D':0, 'E':0, 'F':0}
- calceqn(eqn2,dict2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement