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,list):
- for i in list:
- eqn[i] = input(i[0]+'=')
- if eqn['A'] == 0 and eqn['B'] == 0:
- raise TypeError("No Both Zero!")
- def simeqn(eqn,list):
- eqn_gcd = gcd(eqn.values())
- print eqn_gcd
- for i in list:
- eqn[i] = eqn[i]/abs(eqn_gcd)
- def printeqn(eqn,list):
- eqn_text = ''
- for i in list:
- if eqn[i]>0 and i!='A': eqn_text+= '+'
- eqn_text += str(eqn[i])+list[i]
- print eqn_text+'=0'
- def calceqn(eqn,list):
- readeqn(eqn,list)
- simeqn(eqn,list)
- printeqn(eqn,list)
- # -- Read eqn1 --
- print 'Type Ax²+By²+C=0'
- list = ['A','B','C']
- list1 = {'A':'x', 'B':'y', 'C':''}
- eqn1 = {'A': 0, 'B': 0, 'C': 0}
- calceqn(eqn1,list1)
- # -- READ eqn2 --
- print 'Type Ax²+By²+Dx+Ey+F=0'
- list = ['A','B','D','E','F']
- list2 = {'A':'x²', 'B':'y²', 'D':'x', 'E':'y', 'F':''}
- eqn2 = {'A':0, 'B':0, 'D':0, 'E':0, 'F':0}
- calceqn(eqn2,list2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement