Advertisement
Guest User

Untitled

a guest
Feb 11th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.11 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,list):
  16.     for i in list:
  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,list):
  22.     eqn_gcd = gcd(eqn.values())
  23.     print eqn_gcd
  24.     for i in list:
  25.         eqn[i] = eqn[i]/abs(eqn_gcd)
  26.  
  27. def printeqn(eqn,list):
  28.     eqn_text = ''
  29.     for i in list:
  30.         if eqn[i]>0 and i!='A': eqn_text+= '+'
  31.         eqn_text += str(eqn[i])+list[i]
  32.     print eqn_text+'=0'
  33.  
  34. def calceqn(eqn,list):
  35.     readeqn(eqn,list)
  36.     simeqn(eqn,list)
  37.     printeqn(eqn,list)
  38.  
  39. # -- Read eqn1 --
  40. print 'Type Ax²+By²+C=0'
  41. list = ['A','B','C']
  42. list1 = {'A':'x', 'B':'y', 'C':''}
  43. eqn1 = {'A': 0, 'B': 0, 'C': 0}
  44.  
  45. calceqn(eqn1,list1)
  46.  
  47. # -- READ eqn2 --
  48. print 'Type Ax²+By²+Dx+Ey+F=0'
  49. list = ['A','B','D','E','F']
  50. list2 = {'A':'x²', 'B':'y²', 'D':'x', 'E':'y', 'F':''}
  51. eqn2 = {'A':0, 'B':0, 'D':0, 'E':0, 'F':0}
  52.  
  53. calceqn(eqn2,list2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement