Professional Documents
Culture Documents
22BCE11442
Practice Set 4
Nikhil Rai
22BCE11442
Q1) Write a Python program to create a file where all letters of English alphabet
are listed by specified number of letters on each line.
OUT
PUT
OUTPUT
Q3) Write a Python program to combine each line from first file with the
corresponding line in second file.
Code
OUTPUT
Nikhil Rai
22BCE11442
Q4) Write a Python program to create a table and insert some records in that
table. Finally selects all rows from the table and display the records.
Code
import sqlite3
def create_table(cursor):
cursor.execute('''
CREATE TABLE IF NOT EXISTS example_table (
id INTEGER PRIMARY KEY,
name TEXT,
age INTEGER
)
''')
def insert_record(cursor, name, age):
cursor.execute("INSERT INTO example_table (name, age) VALUES (?, ?)",
(name, age))
def display_records(cursor):
cursor.execute("SELECT * FROM example_table")
rows = cursor.fetchall()
print("ID | Name | Age")
print("-----------------")
for row in rows:
print(f"{row[0]} | {row[1]} | {row[2]}")
def main():
conn = sqlite3.connect('example.db')# Connect to a SQLite database (or
create one if it doesn't exist)
cursor = conn.cursor()# Create a cursor object to interact with the
database
Nikhil Rai
22BCE11442
OUTPUT
Q5) Write a Python program to display the details of jobs in descending sequence
on job title.
------------+---------------------------------+------------+------------+
| JOB_ID | JOB_TITLE | MIN_SALARY | MAX_SALARY |
+------------+---------------------------------+------------+------------+
| AD_PRES | President | 20080 | 40000 |
| AD_VP | Administration Vice President | 15000 | 30000 |
| AD_ASST | Administration Assistant | 3000 | 6000 |
Nikhil Rai
22BCE11442
| FI_MGR | Finance Manager | 8200 | 16000 |
| FI_ACCOUNT | Accountant | 4200 | 9000 |
| AC_MGR | Accounting Manager | 8200 | 16000 |
| AC_ACCOUNT | Public Accountant | 4200 | 9000 |
| SA_MAN | Sales Manager | 10000 | 20080 |
| SA_REP | Sales Representative | 6000 | 12008 |
| PU_MAN | Purchasing Manager | 8000 | 15000 |
| PU_CLERK | Purchasing Clerk | 2500 | 5500 |
| ST_MAN | Stock Manager | 5500 | 8500 |
| ST_CLERK | Stock Clerk | 2008 | 5000 |
| SH_CLERK | Shipping Clerk | 2500 | 5500 |
| IT_PROG | Programmer | 4000 | 10000 |
| MK_MAN | Marketing Manager | 9000 | 15000 |
| MK_REP | Marketing Representative | 4000 | 9000 |
| HR_REP | Human Resources Representative | 4000 | 9000 |
| PR_REP | Public Relations Representative | 4500 | 10500 |
+------------+---------------------------------+------------+------------+
Code
from prettytable import PrettyTable
# Data for the jobs
jobs_data = [
["AD_PRES", "President", 20080, 40000],
["AD_VP", "Administration Vice President", 15000, 30000],
["AD_ASST", "Administration Assistant", 3000, 6000],
["FI_MGR", "Finance Manager", 8200, 16000],
["FI_ACCOUNT", "Accountant", 4200, 9000],
["AC_MGR", "Accounting Manager", 8200, 16000],
["AC_ACCOUNT", "Public Accountant", 4200, 9000],
["SA_MAN", "Sales Manager", 10000, 20080],
["SA_REP", "Sales Representative", 6000, 12008],
["PU_MAN", "Purchasing Manager", 8000, 15000],
["PU_CLERK", "Purchasing Clerk", 2500, 5500],
["ST_MAN", "Stock Manager", 5500, 8500],
["ST_CLERK", "Stock Clerk", 2008, 5000],
["SH_CLERK", "Shipping Clerk", 2500, 5500],
["IT_PROG", "Programmer", 4000, 10000],
["MK_MAN", "Marketing Manager", 9000, 15000],
["MK_REP", "Marketing Representative", 4000, 9000],
["HR_REP", "Human Resources Representative", 4000, 9000],
Nikhil Rai
22BCE11442