Mini Project Using Python Made by Wasi
Mini Project Using Python Made by Wasi
class Node:
def __init__(self,data):
self.data=data
self.next=None
class Linked_List:
def __init__(self):
self.head=None
self.tail=None
self.counter=0
def Add_in_last(self,data):
node=Node(data)
if self.head is None:
self.head=node
self.tail=node
self.counter+=1
else:
self.tail.next=node
self.tail=node
self.counter+=1
def Add_in_begin(self,data):
node=Node(data)
if self.head is None:
self.head=node
self.counter+=1
self.tail=node
else:
node.next=self.head
self.counter+=1
self.head=node
def Add_mid_bef(self,data,bef):
node=Node(data)
if self.head is None:
print("Linked List is empty !")
elif self.head.data==bef:
node.next=self.head
self.counter+=1
self.head=node
else:
temp=self.head
while temp is not None:
if temp.next is not None and temp.next.data==bef:
node.next=temp.next
self.counter += 1
temp.next=node
break
temp=temp.next
else:
print("Value is not Exist !")
def Add_value(self,index,new_list):
if index==0:
self.head.data.append(new_list)
else:
counter=1
temp=self.head.next
while counter<=index:
if counter==index:
temp.data.append(new_list)
break
counter+=1
temp=temp.next
def Update_values(self,index,e_index,new_index):
if index==0:
self.head.data[e_index]=new_index
else:
i=1
temp=self.head.next
while i<=index:
if i==index:
temp.data[e_index]=new_index
break
i+=1
temp=temp.next
def Add_mid_after(self,data,after):
node=Node(data)
if self.head is None:
print("Linked List is empty")
else:
temp=self.head
while temp is not None:
if temp.data==after:
if temp.next:
node.next=temp.next
self.counter += 1
temp.next=node
break
else:
self.tail.next=node
self.counter += 1
self.tail=node
break
temp=temp.next
else:
print("Value is not Exist")
def Print(self):
if self.head is None:
print("Linked List is empty")
else:
temp=self.head
while temp is not None:
print(temp.data,end="==>")
temp=temp.next
else:
print(None)
def Delete(self,index):
if index==0:
self.head=self.head.next
else:
counter=1
temp=self.head
while temp is not None:
if counter==index:
temp.next=temp.next.next
break
temp=temp.next
counter+=1
def Show_Detail(self,index):
if index==0:
return self.head.data
else:
temp=self.head.next
counter=1
while temp is not None:
if counter==index:
return temp.data
temp=temp.next
class Stack:
def __init__(self):
self.top=None
self.counter=0
def Push(self,data):
node=Node(data)
if self.top is None:
self.top=node
self.counter+=1
else:
node.next=self.top
self.counter+=1
self.top=node
def Pop(self):
value=self.top.data
self.counter -= 1
self.top=self.top.next
return value
def Peek(self):
value=self.top.data
return value
class Queue:
def __init__(self):
self.front=None
self.rear=None
self.counter=0
def Enqueue(self,data):
node=Node(data)
if self.front is None:
self.front=node
self.rear=node
self.counter+=1
else:
self.rear.next=node
self.counter+=1
self.rear=node
def Dqueue(self):
value=self.front.data
self.front=self.front.next
self.counter-=1
return value
def Peek(self):
value=self.front.data
return value
class Tree_Node:
def __init__(self,data):
self.data=data
self.left=None
self.right=None
class Tree:
def Insertion(self,root,key):
if root is None:
new_node=Tree_Node(key)
root=new_node
return root
queue=Queue()
queue.Enqueue(root)
while queue.counter>0:
popped_node=queue.Dqueue()
if popped_node.left is None:
new_node=Tree_Node(key)
popped_node.left=new_node
break
else:
queue.Enqueue(popped_node.left)
if popped_node.right is None:
new_node=Tree_Node(key)
popped_node.right=new_node
break
else:
queue.Enqueue(popped_node.right)
return root
def Print(self,root):
if root is None:
return
print(root.data)
self.Print(root.left)
self.Print(root.right)
def Performance(self,root):
queue=Queue()
queue.Enqueue(root)
while queue.counter>0:
popped_node=queue.Dqueue()
print(f"{popped_node.data[0]}'Total Marks are
{popped_node.data[1]}")
if popped_node.left is not None:
queue.Enqueue(popped_node.left)
if popped_node.right is not None:
queue.Enqueue(popped_node.right)
class Priority_Node:
def __init__(self,data,priority):
self.data=data
self.priority=priority
class Max_Heap:
def __init__(self):
self.heap=[]
def Insertion(self,data,priority):
node=Priority_Node(data,priority)
self.heap.append(node)
self.Heapify_Up(len(self.heap)-1)
def Deletion(self):
self.heap[0]=self.heap[len(self.heap)-1]
self.heap.pop(len(self.heap)-1)
self.Heapify_Down(len(self.heap)-1)
def Heapify_Up(self,index):
while index>0:
parent=(index-1)//2
if self.heap[index].priority>self.heap[parent].priority:
self.Swap(parent,index)
index=parent
else:
break
def Heapify_Down(self,index):
max_index=index
parent=0
while True:
left_child=(2 * parent)+ 1
right_child=(2 * parent)+ 2
if left_child>max_index:
left_child=None
if right_child>max_index:
right_child=None
if left_child is None and right_child is None:
break
if right_child is not None and
self.heap[parent].priority>self.heap[left_child].priority and
self.heap[parent].priority>self.heap[right_child].priority:
break
if right_child and
self.heap[parent].priority>self.heap[left_child].priority and
self.heap[parent].priority>self.heap[right_child].priority:
break
if right_child and
self.heap[left_child].priority>self.heap[parent].priority and
self.heap[left_child].priority>self.heap[right_child].priority:
self.Swap(parent,left_child)
parent=left_child
elif right_child and
self.heap[right_child].priority>self.heap[parent].priority and
self.heap[right_child].priority>self.heap[left_child].priority:
self.Swap(parent,right_child)
parent=right_child
elif right_child is None and
self.heap[left_child].priority>self.heap[parent].priority:
self.Swap(parent,left_child)
parent=left_child
else:
break
def Swap(self,parent,index):
temp=self.heap[parent]
self.heap[parent]=self.heap[index]
self.heap[index]=temp
def Print(self):
for x in self.heap:
print(f"Name {x.data} Marks {x.priority}")
class SMS:
def __init__(self):
self.std_courses = []
self.std_marks=[]
self.std_name = []
class LMS:
print("Welcome in Student Management System ")
def __init__(self):
print("1. Add Student ")
print("2. Inquires")
print("3. Undo ")
print("4. Already Enrolled")
print("5. Top Students ")
print("6. Departments")
print("7. Student's Performance")
print("8. Exit !")
try:
choice = int(input("Enter Choice : "))
if choice == 1:
self.Add_Student()
elif choice == 2:
name = input("Enter name : ")
if name not in self.node.std_name:
print("Not Exist !")
self.__init__()
else:
index = self.node.std_name.index(name)
self.Inquiries(index)
elif choice == 3:
self.Undo()
elif choice == 4:
name = input("Enter your name : ")
if name in self.node.std_name:
f_index = self.node.std_name.index(name)
self.Information(f_index)
else:
print("Not Exist")
self.__init__()
elif choice==5:
if len(self.node.std_name) >= 1:
self.Top_Student()
self.__init__()
else:
print("No Valid Information !")
self.__init__()
elif choice == 6:
self.Department()
elif choice == 7:
if len(self.node.std_name)>=1:
self.Student_Performance()
self.__init__()
else:
print("Empty Record !")
self.__init__()
elif choice==8:
print("Thanks For using Program !")
return
else:
print("Thanks For using Program !")
return
except ValueError as e:
print(e)
self.__init__()
except:
print("Something Went Wrong !")
node=SMS()
l_list=Linked_List()
stack=Stack()
queue2=Queue()
def Top_Student(self):
max_heap=Max_Heap()
for index,x in enumerate(self.node.std_marks):
total=0
for value in x:
total+=value
max_heap.Insertion(self.node.std_name[index],total)
max_heap.Print()
def Student_Performance(self):
tree=Tree()
sum_all=0
for x in self.node.std_marks[0]:
sum_all+=x
root=Tree_Node([self.node.std_name[0],sum_all])
if len(self.node.std_marks)>1:
save_len=len(self.node.std_marks)
i=1
while i<save_len:
total = 0
for x in self.node.std_marks[i]:
total+=x
tree.Insertion(root,[self.node.std_name[i],total])
i+=1
else:
tree.Performance(root)
else:
tree.Performance(root)
def Department(self):
science=Tree()
root=Tree_Node("Chemistry")
science.Insertion(root,"Physics")
science.Insertion(root,"Biology")
science.Insertion(root,"Geology")
root=science.Insertion(root,"Astronomy")
print("Science Department is offering")
science.Print(root)
print()
arts=Tree()
root=Tree_Node("History")
arts.Insertion(root,"Literature")
arts.Insertion(root,"Philosophy")
arts.Insertion(root,"Fine Arts")
root=arts.Insertion(root,"Performing Arts")
print("Arts Department is offering")
arts.Print(root)
print()
Engineering = Tree()
root = Tree_Node("Computer Science")
Engineering.Insertion(root, "Electrical Engineering")
Engineering.Insertion(root, "Mechanical Engineering")
Engineering.Insertion(root, "Civil Engineering")
root = Engineering.Insertion(root, "Chemical Engineering")
print("Engineering Department is offering")
Engineering.Print(root)
print()
self.__init__()
def Add_Student(self):
name=input("Enter name : ")
if name not in self.node.std_name:
self.node.std_name.append(name)
courses_list=[]
print("You can choose any 3 subject")
for x in range(1,4):
courses_list.append(input(f"Enter "+str(x)+" Subject Name
: "))
self.node.std_courses.append([courses_list[0],courses_list[1],courses_list
[2]])
list1=[f"Added_course_name
{name}",name,courses_list[0],courses_list[1],courses_list[2]]
self.stack.Push(list1)
list2=[name,[courses_list[0],courses_list[1],courses_list[2]]]
self.l_list.Add_in_last(list2)
print(f"Added {name} !")
self.Add_marks()
else:
print("Already Exist")
self.__init__()
def Add_marks(self):
Student_name=len(self.node.std_courses)-1
save_list=self.node.std_courses[len(self.node.std_courses)-1]
node_list=[]
for x in save_list:
node_list.append(int(input("Enter "+ x +" Marks : ")))
self.node.std_marks.append(node_list)
self.l_list.Add_value(Student_name,node_list)
marks_list=[]
marks_list.insert(0, "Marks")
marks_list.insert(1, self.node.std_name[Student_name])
for x in node_list:
marks_list.append(x)
self.stack.Push(marks_list)
print(f"Added {self.node.std_name[Student_name]}'s Marks !")
self.__init__()
def Inquiries(self,index):
print("1. Wanna Update Your name")
print("2. Wanna Update Your Courses")
print("3. Wanna Update Your Marks")
print("4. Wanna See Information")
print("5. Wanna leave Academy")
requests=int(input("Tell us the quantity of request (1,2,3) Which
you have : "))
i=0
queue=Queue()
while i<requests:
queue.Enqueue(int(input("Enter Request # : (1,2,3) : ")))
i+=1
while queue.counter>0:
popped_value=queue.Dqueue()
if popped_value==1:
name=input("Enter new name : ")
self.Update_name(name,index)
elif popped_value==2:
list1=[]
i=1
while i<=3:
list1.append(input("Enter the "+ str(i) +" Course name
: "))
i+=1
self.Update_Courses(list1,index)
elif popped_value==3:
self.Update_Marks(index)
elif popped_value==4:
self.Print(index)
elif popped_value==5:
while queue.counter>0:
queue.Dqueue()
if queue.counter==0:
self.Delete(index)
else:
self.Delete(index)
elif popped_value==6:
self.l_list.Print()
if queue.counter==0:
self.__init__()
def Delete(self,index):
list1=["d"]
list1.append(self.node.std_name[index])
list1.append(self.node.std_courses[index])
list1.append(self.node.std_marks[index])
self.l_list.Delete(index)
self.node.std_name.pop(index)
self.node.std_courses.pop(index)
self.node.std_marks.pop(index)
self.stack.Push(list1)
print("Successfully Deleted")
def Print(self,index):
print(f"Student name is {self.node.std_name[index]}")
print(f"{self.node.std_courses[index][0]} :-
{self.node.std_marks[index][0]},{self.node.std_courses[index][1]} :-
{self.node.std_marks[index][1]},{self.node.std_courses[index][2]} :-
{self.node.std_marks[index][2]}")
def Update_Courses(self,new_list1,index):
old_list=self.node.std_courses[index]
self.node.std_courses[index]=new_list1
self.l_list.Update_values(index,1,new_list1)
mega_list=["c",index,old_list]
print("Changed Courses name !")
self.stack.Push(mega_list)
return
def Update_name(self,name,index):
old_name=self.node.std_name[index]
list1=["n",name,old_name]
self.stack.Push(list1)
self.l_list.Update_values(index,0,name)
self.node.std_name[index]=name
print(f"Change {old_name}'s name in {name}")
def Update_Marks(self,index):
mark1,mark2,mark3=self.node.std_marks[index][0],self.node.std_marks[index]
[1],self.node.std_marks[index][2]
list1=["updated_marks",self.node.std_name[index],mark1,mark2,mark3]
self.stack.Push(list1)
courses_list=self.node.std_courses[index]
for index2,x in enumerate(courses_list):
self.node.std_marks[index][index2]=int(input("Enter "+str(x)+"
Marks : "))
self.l_list.Update_values(index,2,[self.node.std_marks[index][0],self.node
.std_marks[index][1],self.node.std_marks[index][2]])
print(f"Marks Updated For {self.node.std_name[index]}")
self.Show_Detail(index)
def Information(self,index):
data=self.l_list.Show_Detail(index)
print(f"Student name is {data[0]}!")
for x in range(0,3,1):
print(f"Student's {x+1} subject is {data[1][x]} and Score is
{data[2][x]}")
self.__init__()
def Undo(self):
if self.stack.counter>=1:
save = self.stack.Peek()
if save[0].lower() == "updated_marks": # Updated_marks
self.stack.Pop()
save_name=save[1]
find_index=self.node.std_name.index(save_name)
# self.node.std_name[len_list] = save[1]
self.node.std_marks[find_index][0]=save[2]
self.node.std_marks[find_index][1] = save[3]
self.node.std_marks[find_index][2] = save[4]
list2 = [save[2],save[3],save[4]]
self.l_list.Update_values(find_index,2,list2)
# self.l_list.Update_values()
print(f"Undo {self.node.std_name[find_index]}'s
Marks")
self.__init__()
elif save[0][0].lower() == "a":#name & courses
self.stack.Pop()
save_name=save[1]
save_index=self.node.std_name.index(save_name)
self.l_list.Delete(save_index)
print(f"Removed {self.node.std_name[save_index]} from
system !")
self.node.std_courses.pop(save_index)
self.node.std_name.pop(save_index)
self.node.std_marks.pop(save_index)
self.__init__()
elif save[0][0].lower()=="m":# Deleted_marks
self.stack.Pop()
save_index=save[1]
find_index=self.node.std_name.index(save_index)
self.node.std_marks[find_index][0]=0
self.node.std_marks[find_index][1]=0
self.node.std_marks[find_index][2]=0
self.l_list.Update_values(find_index,2,[0,0,0])
print(f"Removed {save[1]}'s Marks")
self.__init__()
elif save[0][0].lower()=="n": # Updated_name
list1=self.stack.Pop()
new_name=list1[1]
name_index=self.node.std_name.index(new_name)
self.node.std_name[name_index]=list1[2]
self.l_list.Update_values(name_index,0,[list1[2]])
print(f"Changed {new_name} into {list1[2]} ")
self.__init__()
elif save[0][0]=="c": # Updated_Courses
list1=self.stack.Pop()
self.node.std_courses[list1[1]]=list1[2]
self.l_list.Update_values(list1[1],1,list1[2])
print(f"Changed new courses in old")
self.__init__()
elif save[0][0]=="d": # Deleted_items
list1=self.stack.Pop()
self.node.std_name.append(list1[1])
self.node.std_courses.append(list1[2])
self.node.std_marks.append(list1[3])
list2=[list1[1],list1[2],list1[3]]
self.l_list.Add_in_last(list2)
print(f"Added {list1[1]}'s information")
self.__init__()
else:
print("No tasks for undo !")
self.__init__()
def Show_Detail(self,index):
print(self.node.std_name[index])
courses_list=self.node.std_courses[index]
print(f"{courses_list[0]}:-{self.node.std_marks[index][0]}
,{courses_list[1]} :-{self.node.std_marks[index][1]} ,{courses_list[2]} :-
{self.node.std_marks[index][2]}")
node=LMS()