Final Output Program
Final Output Program
#1. A program that will print all the elements of the array one by one.
print(element)
#2. This program in python will ask the user if how many names to store in the list and will ask again
to input those names and will print it out.
n = input()
arr = []
n = int(n)
for i in range(n):
Names = input()
arr.append(Names)
for i in range(n):
#1. A program in python that will create a 2D array with 4 rows and 5 columns and will display the first
and third row. And will print also the first row's third element and the third row's forth element.
array=[[5,10,15,20,25],[30,35,40,45,50],[55,60,65,70,75,],[80,85,90,95,100]]
print(array)
print(array[0])
print(array[2])
print(array[0][2])
print(array[2][3])
#2. Another 2D program in python that has three rows and five columns and will delete the row
values in the Third and second row and will print out the remaining rows.
array=[[23,45,43,23,45],[45,67,54,32,45],[89,90,87,65,44]]
del array[2]
del array[1]
print(array)
def program_2():
#LINKEDLIST
class Node:
self.data = data
self.next = None
class insdelion:
def __init__(self):
self.head = None
self.last_node = None
def append(self, data):
if self.last_node is None:
self.head = Node(data)
self.last_node = self.head
else:
self.last_node.next = Node(data)
self.last_node = self.last_node.next
if self.head is None:
return
index = 0
current = self.head
previous = current
current = current.next
index += 1
elif index == 0:
self.head = self.head.next
else:
previous.next = current.next
def display(self):
current = self.head
current = current.next
while True:
print()
lstchoice=(input("press'a' for insertion of element\n press 'b' for deletion \n press 'c' to quit"))
if lstchoice=='a':
a_llist = insdelion()
for i in range(n):
a_llist.append(data)
a_llist.display();
elif lstchoice=='b':
llist = insdelion()
llist.display()
llist.deleteNode(position)
elif lstchoice=="c":
break;
else:
print("NO Match")
def program_3():
# Creating a stack
def create_stack():
stack = []
return stack
def check_empty(stack):
return len(stack) == 0
stack.append(item)
if (check_empty(stack)):
return stack.pop()
stack = create_stack()
push(stack, str(7))
push(stack, str(9))
push(stack, str(13))
push(stack, str(21))
def program_4():
favs = []
while True:
data = input()
if str.lower(data) == "q":
break
print("removing:", favs.pop(0))
else:
favs.append(data)
print(favs)
queue=[]
def enqueue():
queue.append(element)
def dequeue():
if not queue:
print("queue is empty!")
else:
e = queue.pop(0)
print("remove element:", e)
def display():
print(queue)
while True:
choice = int(input())
if choice==1:
enqueue()
elif choice==2:
dequeue()
elif choice==3:
display()
elif choice==4:
break
else:
def program_5():
#Binary tree
def inorder():
# Binary Tree
class Node:
self.left = None
self.right = None
self.val = key
def printInorder(root):
if root:
# First recur on left child
printInorder(root.left)
print(root.val),
printInorder(root.right)
# Driver code
if __name__ == "__main__":
root = Node(1)
root.left = Node(2)
root.right = Node(3)
root.left.left = Node(4)
root.left.right = Node(5)
# Function call
printInorder(root)
def preorder():
# Binary Tree
class Node:
self.left = None
self.right = None
self.val = key
def printPreorder(root):
if root:
print(root.val),
printPreorder(root.left)
printPreorder(root.right)
# Driver code
if __name__ == "__main__":
root = Node(1)
root.left = Node(2)
root.right = Node(3)
root.left.left = Node(4)
root.left.right = Node(5)
# Function call
printPreorder(root)
def postorder():
# Binary Tree
class Node:
self.left = None
self.right = None
self.val = key
def printPostorder(root):
if root:
printPostorder(root.left)
printPostorder(root.right)
print(root.val),
# Driver code
if __name__ == "__main__":
root = Node(1)
root.left = Node(2)
root.right = Node(3)
root.left.left = Node(4)
root.left.right = Node(5)
# Function call
printPostorder(root)
while True:
print()
if case==1:
preorder()
break;
elif case==2:
inorder()
break;
elif case==3:
postorder()
break;
else :
def program_6():
nOne = int(input())
nTwo = int(input())
if ch=='+':
elif ch=='-':
elif ch=='*':
elif ch=='/':
else:
print("\nInvalid Operator!")
while True:
print()
case = int(input("Select a program to run \n1.array \n2.linked list \n3.stacks \n4.queues \n5.binary
trees\n6.arithmetic operations\n"))
if case==1:
program_1()
break;
elif case==2:
program_2()
break;
elif case==3:
program_3()
break;
elif case==4:
program_4()
break;
elif case==5:
program_5()
break;
elif case==6:
program_6()
break;
else :