Python code

# Python code goes here:
stack = []
while True:
    print("
Choose an operation:")
    print("1. PUSH (Add city)")
    print("2. POP (Remove city)")
    print("3. DISPLAY (Show cities)")
    print("4. EXIT")

    choice = input("Enter your choice (1/2/3/4): ")

    if choice == '1':
        pin_code = input("Enter the pin code of the city: ")
        city_name = input("Enter the name of the city: ")
        stack.append((pin_code, city_name))
        print("City '" + city_name + "' with pin code '" + pin_code + "' added to the stack.")

    if choice == '2':
        if len(stack) > 0:
          city = stack.pop()
          print("City '" + city[1] + "' with pin code '" + city[0] + "' removed from the stack.")
        else:
          print("empty stack")

    if choice == '3':
        if len(stack) > 0:
          print("Cities in the stack:")
          index = len(stack) - 1
          while index >= 0:
            city = stack[index]
            print("Pin Code: " + city[0] + ", City: " + city[1])
            index -= 1
        else:
          print("empty stack")

    if choice == '4':
        print("Exiting the program.")
        break

    else:
        print("Invalid choice")
Download Python Code

SQL Basics and Products Table Queries

Here are some basic SQL commands and specific queries for the Products table:

  • How to Create a Table:
  • CREATE TABLE Products (
        Pcode VARCHAR(10),
        Pname VARCHAR(50),
        Qty INT,
        Price DECIMAL(10, 2),
        Company VARCHAR(50)
    );
                    
  • SQL Queries for Products Table:
  • -- 1. Display maximum price of products
    SELECT MAX(Price) AS MaxPrice FROM Products;
    
    -- 2. Display unique products from the table
    SELECT DISTINCT Pname FROM Products;
    
    -- 3. Display the product number, product name, and company in the descending order of their price
    SELECT Pcode, Pname, Company FROM Products ORDER BY Price DESC;
    
    -- 4. Display details of products whose company name ends with 'e'
    SELECT * FROM Products WHERE Company LIKE '%e';