shreyansh report file
shreyansh report file
SESSION:2024-25
COMPUTER SCIENCE (083)
REPORT FILE
..………………………..
Teacher Incharge
……………………………… ………………………...
Examiner’s Signature Principal
17. A. To display the names of all the items whose names starts
with “A”.
B. To display ICODEs and INAMEs of all items, whose Brand
name is Reliable or Coscore.
C. To change the Brand name to “Fit Trend India” of the item,
whose ICODE as”G101”.
D. Add a new row for new item in GYM with the details:
“G107”, “XYZ Exerciser”, 21000, “GTC Fitness”.
E. Delete items from table having price greater than 15000.
18. Write a Python code to create the table SALESPERSON with
given structure and constraint.
#__main__
sentence = input("Enter a sentence: ")#function
invoking
print("Capitalised sentence is : ",capitalize(sentence))
OUTPUT:
Q 2. WRITE A FUNCTION THAT ACCEPTS A NO. &
CHECK WHETHER A NO. IS HAPPY NO. OR NOT?
CODE:
#program to check whether a no. is happy no. or not
def is_happy_number(n):
def sum_of_squares(num):
return sum(int(digit) ** 2 for digit in str(num))
visited = set()
while n != 1 and n not in visited:
visited.add(n)
n = sum_of_squares(n)
return n == 1
count_digits = 0
file.close()
# Display the count of digits
print(f"Number of digits in the file: {count_digits}")
def writeRecord():
# Open the file in append mode to add new records
file = open('EmpRecord.csv', mode='a', newline='')
writer = csv.DictWriter(file, fieldnames=['name', 'age', 'salary'])
file.close()
def displayRecord():
# Open the file
file = open('EmpRecord.csv', mode='r')
reader = csv.DictReader(file)
file.close()
print("Data for 5 students has been written to 'Record.csv'.")
def CreateFile():
if file.tell() == 0:
writer.writeheader()
def DisplayRec():
file.close()
print("Choose an option:")
print("1. Add a new book record")
print("2. Display all book records")
import pickle
def get_data():
data = {}
for i in range(5):
name = input(f"Enter name of employee {i + 1}: ")
salary = float(input(f"Enter salary of {name}: "))
data[name] = salary
return data
# Pop a book
print("\nPopped book:", pop(book_stack))
B.
C.
D.
E.
Q 18. Write a Python code to create the table
SALESPERSON with given structure and constraint.
CODE:
import mysql.connector
conn=mysql.connector.connect(host="localhost",user="root",password=
"root ",database="computer")
conn = mysql.connector.connect(
host="localhost",
user="root",
password="root ",
database="employee"
)
cursor = conn.cursor()
cursor.execute('''
CREATE TABLE IF NOT EXISTS Employee (
EmpNo INT PRIMARY KEY,
Name VARCHAR(100) NOT NULL,
Age INT NOT NULL,
Salary DECIMAL(10, 2) NOT NULL
)
''')
emp_no = int(input("Enter Employee Number (EmpNo): "))
name = input("Enter Employee Name: ")
age = int(input("Enter Employee Age: "))
salary = float(input("Enter Employee Salary: "))
cursor.execute('''
INSERT INTO Employee (EmpNo, Name, Age, Salary)
VALUES (%s, %s, %s, %s)
''', (emp_no, name, age, salary))
def create_table():
# Connect to the database
conn = mysql.connector.connect(
host="localhost",
user="root",
password="root ",
database="product"
)
cursor = conn.cursor()
def insert_sample_data():
# Connecting to the database
conn = mysql.connector.connect(
host="localhost",
user="root",
password="Tiger@1234",
database="product"
)
cursor = conn.cursor()
def update_price():
# Connect to the database
conn = mysql.connector.connect(
host="localhost",
user="root",
password="root",
database="product"
)
cursor = conn.cursor()
# Update prices by 5%
cursor.execute('''
UPDATE Product
SET Price = Price * 1.05
''')
conn.commit() # Commit the changes
print("Prices updated by 5%.")
conn.close() # Close the connection
def display_products():
# Connect to the database
conn = mysql.connector.connect(
host="localhost",
user="root",
password="root",
database="product"
)
cursor = conn.cursor()
def del_record(name):
db = mysql.connector.connect(
host="localhost",
user="root",
password="root",
database="school"
)
cur = db.cursor()
if rec:
# Print details of the record to be deleted
print("Deleting the following record:")
print(f"ID: {rec[0]}, Name: {rec[1]}, Details: {rec[2:]}")