Created
October 14, 2011 18:17
-
-
Save gceylan/1287874 to your computer and use it in GitHub Desktop.
polinom
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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