Solution - Practical QP
Solution - Practical QP
def pop(stack):
if not stack:
print("Stack is empty! Nothing to pop.")
else:
print(f"Popped element: {stack.pop()}")
def display(stack):
if not stack:
print("Stack is empty!")
else:
print("Stack elements are:")
for element in reversed(stack):
print(element)
def main():
stack = []
while True:
print("\nMenu:")
print("1. Push")
print("2. Pop")
print("3. Display")
print("4. Exit")
choice = input("Enter your choice (1-4): ")
if choice == "1":
element = input("Enter the element to push: ")
push(stack, element)
elif choice == "2":
pop(stack)
elif choice == "3":
display(stack)
elif choice == "4":
print("Exiting the program.")
break
else:
print("Invalid choice! Please try again.")
if _name_ == "_main_":
main()
2. SQL Commands:
def main():
filename = "students.dat"
while True:
print("\nMenu:")
print("1. Create File")
print("2. Search Roll Number")
print("3. Exit")
choice = input("Enter your choice (1-3): ")
if choice == "1":
create_file(filename)
elif choice == "2":
rollno = input("Enter roll number to search: ")
search_file(filename, rollno)
elif choice == "3":
print("Exiting the program.")
break
else:
print("Invalid choice! Please try again.")
if _name_ == "_main_":
main()
2. SQL Commands: