def create_and_write_file():
    with open("myself.txt", "w") as file:
        file.write("Hello, my name is Alex.\n")
        file.write("I am passionate about programming and technology.\n")
        file.write("I enjoy learning new skills and solving challenges.\n")

def append_and_display_file():
    additional_content = (
        "I believe in lifelong learning and personal growth.\n"
        "My goal is to contribute to impactful projects in the tech world.\n"
    )

    # Append content while trimming unnecessary whitespaces
    with open("myself.txt", "a") as file:
        file.write(additional_content.strip() + "\n")  # Strip unwanted spaces and ensure the line ends properly

    with open("myself.txt", "r") as file:
        content = file.read().strip()  # Remove leading/trailing spaces
        print("\nContents of the file:\n")
        print(content)

    with open("myself.txt", "r") as file:
        lines = file.readlines()

        n = 0
        word_count = 0
        char_count = 0

        for ln in lines:
            ln = ln.strip()  # Strip leading/trailing spaces for each line
            if ln:  # Avoid counting empty lines
                n += 1  
                word_count += len(ln.split())  
                char_count += len(ln)  

    print("\nStatistics:")
    print(f"Number of lines: {n}")
    print(f"Number of words: {word_count}")
    print(f"Number of characters: {char_count}")

create_and_write_file()
append_and_display_file()
    
     

CREATE DATABASE office;

USE office;

CREATE TABLE employees (
    EmployeeID INT PRIMARY KEY,
    EmployeeName VARCHAR(50),
    Department VARCHAR(50),
    Salary INT,
    Age INT
);

CREATE TABLE Projects (
    ProjectID INT PRIMARY KEY,
    ProjectName VARCHAR(50) NOT NULL,
    EmployeeID INT NOT NULL,
    Budget DECIMAL(12, 2) NOT NULL,
    FOREIGN KEY (EmployeeID) REFERENCES employees(EmployeeID)
);

INSERT INTO employees VALUES (1, 'John Smith', 'IT', 60000, 28);
INSERT INTO employees VALUES (2, 'Sarah Johnson', 'HR', 55000, 35);
INSERT INTO employees VALUES (3, 'Michael Brown', 'IT', 72000, 30);
INSERT INTO employees VALUES (4, 'Emily Davis', 'Finance', 65000, 40);
INSERT INTO employees VALUES (5, 'David Wilson', 'IT', 50000, 25);
INSERT INTO employees VALUES (6, 'Laura Taylor', 'HR', 58000, 29);

INSERT INTO Projects VALUES (101, 'Cloud Migration', 1, 200000);
INSERT INTO Projects VALUES (102, 'Recruitment', 2, 150000);
INSERT INTO Projects VALUES (103, 'Security Upgrade', 3, 180000);
INSERT INTO Projects VALUES (104, 'Financial Audit', 4, 220000);
INSERT INTO Projects VALUES (105, 'App Development', 1, 170000);
INSERT INTO Projects VALUES (106, 'Team Building', 2, 120000);

SSELECT EmployeeName FROM employees WHERE Department = 'IT';

UPDATE employees SET Salary = Salary + (Salary * 10/100);

SELECT E.EmployeeName, P.ProjectName
FROM employees E, Projects P
WHERE E.EmployeeID = P.EmployeeID;

SELECT Department, AVG(Salary) AS AverageSalary
FROM employees
GROUP BY Department;
    

Leave a Reply

Your email address will not be published. Required fields are marked *

sign up!

We’ll send you the hottest deals straight to your inbox so you’re always in on the best-kept software secrets.