Skip to content

Instantly share code, notes, and snippets.

@askn
Created November 24, 2012 22:48
Show Gist options
  • Save askn/4141713 to your computer and use it in GitHub Desktop.
Save askn/4141713 to your computer and use it in GitHub Desktop.
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