Created
November 24, 2012 22:48
-
-
Save askn/4141713 to your computer and use it in GitHub Desktop.
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
class Polinom: | |
def __init__(self, katsayilar): | |
self.katsayilar = katsayilar | |
def __str__(self): | |
denklem = [] | |
for index, katsayi in enumerate(self.katsayilar): | |
us = len(self.katsayilar) - index - 1 | |
if katsayi != 0: | |
if katsayi != 1: | |
if us not in [0, 1]: | |
denklem.append(str(katsayi) + 'x^' + str(us)) | |
elif us == 1: | |
denklem.append(str(katsayi) + "x") | |
else: | |
denklem.append(str(katsayi)) | |
else: | |
if us not in [0, 1]: | |
denklem.append('x^' + str(us)) | |
elif us == 1: | |
denklem.append("x") | |
else: | |
denklem.append(str(katsayi)) | |
return (' + '.join(denklem)) | |
print Polinom([1, 2, 3, 4, 0, 1]) | |
# "x^5 + 2x^4 + 3x^3 + 4x^2 + 1" | |
print Polinom([0, 2, 0, 0]) | |
# 2x^2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment