-
Notifications
You must be signed in to change notification settings - Fork 0
/
polynomial represent.py
39 lines (35 loc) · 1.03 KB
/
polynomial represent.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
class Node:
def __init__(self,coeff,expo):
self.coeff=coeff
self.expo=expo
self.next=None
class List:
def __init__(self):
self.head=None
self.lastnode=None
def append(self,coeff,expo):
if self.head is None:
self.head=Node(coeff,expo)
self.lastnode=self.head
else:
temp=Node(coeff,expo)
self.lastnode.next=temp
self.lastnode=temp
def display(self):
if self.head is None:
print("List is empty ")
else:
current=self.head
while current is not None:
if(current.expo==0):
print("%dx"%(current.coeff))
else:
print("%dx^%d+"%(current.coeff,current.expo)," ")
current=current.next
obj=List()
n=int(input("How many elements wants to enter : "))
for i in range(n):
coeff=int(input("Enter Coefficent : "))
expo=int(input("Enter Exponent : "))
obj.append(coeff,expo)
obj.display()