Skip to content

Instantly share code, notes, and snippets.

@gceylan
Created October 14, 2011 18:17
Show Gist options
  • Save gceylan/1287874 to your computer and use it in GitHub Desktop.
Save gceylan/1287874 to your computer and use it in GitHub Desktop.
polinom
# -*- coding: utf-8 -*-
def eleman_sayilarini_esitle(liste1, liste2, yer, eleman):
n = len(liste1)
m = len(liste2)
while n != m:
if n > m:
liste2.insert(yer, eleman)
m += 1
else:
liste1.insert(yer, eleman)
n += 1
class Polinom:
def __init__(self, *ks):
self.katsayilar = []
self.uzunluk = len(ks)
for i in ks:
self.katsayilar.append(i)
def __str__(self):
n = ''
for i in self.katsayilar:
if i != 0:
if i < 0:
n += '-' + str(abs(i)) + 'x^' + str(self.uzunluk - self.katsayilar.index(i) - 1)
elif i > 0:
n += '+' + str(abs(i)) + 'x^' + str(self.uzunluk - self.katsayilar.index(i) - 1)
return n
def __add__(self, p):
p1 = self.katsayilar
p2 = p.katsayilar
eleman_sayilarini_esitle(p1, p2, 0, 0)
L = len(p1)
p = []
for i in range(0, L):
p.append(p1[i] + p2[i])
return Polinom(p[0], p[1], p[2], p[3]) #işte tam burası , ben çalışıp çalışmadığını anlamak için böyle yaptım. :)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment