Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
9 views

python

The document contains two Python programs: the first program creates a SQLite database for student records, inserts multiple student entries, and then closes the connection; the second program retrieves and prints all records from the database. Additionally, there is a class definition for Matrix that includes methods for adding and multiplying two matrices, demonstrating the functionality with example matrices. The document showcases basic database operations and matrix manipulations in Python.

Uploaded by

Ameya Ranade
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

python

The document contains two Python programs: the first program creates a SQLite database for student records, inserts multiple student entries, and then closes the connection; the second program retrieves and prints all records from the database. Additionally, there is a class definition for Matrix that includes methods for adding and multiplying two matrices, demonstrating the functionality with example matrices. The document showcases basic database operations and matrix manipulations in Python.

Uploaded by

Ameya Ranade
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Assignment 10.

Q1

1st program

import sqlite3

connection = sqlite3.connect("student.db")

crsr = connection.cursor()

sql_command = ''' CREATE TABLE stu(

student_first_name VARCHAR(20),

student_Last_name VARCHAR(20),

Class VARCHAR(10),

PRN_number INTEGER PRIMARY KEY,

Brach VARCHAR(20));'''

crsr.execute(sql_command)

sql_command = '''INSERT INTO stu VALUES ("Ameya","Ranade","2nd year",1,"CS");'''

crsr.execute(sql_command)

sql_command = '''INSERT INTO stu VALUES ("Suyash","Kolhe","2nd year",2,"CS");'''

crsr.execute(sql_command)

sql_command = '''INSERT INTO stu VALUES ("Vedant","Pathak","2nd year",3,"CS");'''

crsr.execute(sql_command)

sql_command = '''INSERT INTO stu VALUES ("Yogesh","Deolkar","2nd year",4,"CS");'''

crsr.execute(sql_command)

sql_command = '''INSERT INTO stu VALUES ("Kalpesh","Mhatre","2nd year",5,"mechanical");'''

crsr.execute(sql_command)

connection.commit()
connection.close()

Q1 2nd program

import sqlite3

connection = sqlite3.connect("student.db")

crsr = connection.cursor()

crsr.execute("SELECT * FROM stu")

ans = crsr.fetchall()

print(ans)

assignment 9

Q1

class Matrix:

pass

def add_matrix(self,mat1,mat2,result):

for i in range(len(mat1)):

for j in range(len(mat1[0])):

result[i][j]=mat1[i][j] + mat2[i][j]

for r in result:

print(r)

def multiplication(self,mat1,mat2,result):

for i in range(len(mat1)):

for j in range(len(mat2[0])):

for k in range(len(mat2)):
result[i][j] += mat1[i][k]*mat2[k][j]

for r in result:

print(r)

M1 = Matrix()

M1.mat1 = [[1,4,5],[8,6,9],[3,6,2]]

M1.mat2 = [[3,6,2],[9,4,5],[6,5,1]]

M1.result =[[0,0,0],[0,0,0],[0,0,0]]

print("\n Adding two matrices \n")

M1.add_matrix(M1.mat1, M1.mat2, M1.result)

print("\n Now multiplying two matrices \n")

M1.multiplication(M1.mat1, M1.mat2, M1.result)

You might also like