Advertisement
Guest User

Untitled

a guest
Feb 11th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.05 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2.  
  3. def gcd(a):
  4.     for i, n in enumerate(a): a[i] = abs(n)
  5.     a.sort()
  6.     min = a[0]
  7.     result = 1
  8.     for i in range(2, min+1):
  9.         flag = True
  10.         for j in a:
  11.             if j % i != 0: flag = False
  12.         if flag == True: result = i
  13.     return result
  14.  
  15. def readeqn(eqn,dictn):
  16.     for i in dictn:
  17.         eqn[i] = input(i[0]+'=')
  18.     if eqn['A'] == 0 and eqn['B'] == 0:
  19.         raise TypeError("No Both Zero!")
  20.  
  21. def simeqn(eqn,dictn):
  22.     eqn_gcd = gcd(eqn.values())
  23.     for i in dictn:
  24.         eqn[i] = eqn[i]/abs(eqn_gcd)
  25.  
  26. def printeqn(eqn,dictn):
  27.     eqn_text = ''
  28.     for i in dictn:
  29.         if eqn[i]>0 and i!='A': eqn_text+= '+'
  30.         eqn_text += str(eqn[i])+dictn[i]
  31.     print eqn_text+'=0'
  32.  
  33. def calceqn(eqn,dictn):
  34.     readeqn(eqn,dictn)
  35.     simeqn(eqn,dictn)
  36.     printeqn(eqn,dictn)
  37.  
  38. # -- Read eqn1 --
  39. print 'Type Ax²+By²+C=0:'
  40. dict1 = {'A':'x', 'B':'y', 'C':''}
  41. eqn1 = {'A': 0, 'B': 0, 'C': 0}
  42. calceqn(eqn1,dict1)
  43.  
  44. # -- READ eqn2 --
  45. print 'Type Ax²+By²+Dx+Ey+F=0:'
  46. dict2 = {'A':'x²', 'B':'y²', 'D':'x', 'E':'y', 'F':''}
  47. eqn2 = {'A':0, 'B':0, 'D':0, 'E':0, 'F':0}
  48. calceqn(eqn2,dict2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement