Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

DO68_RAHULSINHA_EXPERIMENT11

March 27, 2024

[ ]: #DO68_RAHULSINHA_EXPERIMENT11

[4]: ''' 1. Write python program to extract names, and marks of a students␣
↪from following string using regular expression.

'Manav scored 18 marks, Nikhil got 15 marks, Mann done well to get 20 marks,␣
↪whereas Digu got 19 marks'

Output:
Manav 18
Nikhil 15'''

import re

str = 'Manav scored 18 marks, Nikhil got 15 marks, Mann done well to get 20␣
↪marks, whereas Digu got 19 marks'

pattern = r'([A-Za-z]+)\s+[A-Za-z\s]+(\d+)\s+marks'

matches = re.findall(pattern, str)

for match in matches:


name, marks = match
print(name, marks)

Manav 18
Nikhil 15
Mann 20
whereas 19

[6]: '''2. Write a program to check entered website (domain name) is valid or␣
↪not using regular expression.

Ex.
- www.nmims.edu – valid
- @ www.nmims.edu – invalid(started with @)
- .edu – false (“not started with A-Z/a-z etc ”)
'''
import re

1
def is_valid(domain):
reg = r'^www\.[A-Za-z0-9-]+\.[A-Za-z]{2,}$'
return re.match(reg, domain) is not None

domains = ['www.nmims.edu', '@www.nmims.edu', '.edu']


for domain in domains:
print(domain, "- Valid" if is_valid(domain) else "- Invalid")

www.nmims.edu - Valid
@www.nmims.edu - Invalid
.edu - Invalid

[7]: '''3. Write a python program to perform following operations using␣


↪Sqlite and Python.

1. Create Employee Table with Employee number and Employee Name and␣
↪employee salary as attributes.

2. Insert 4-5 records to the table


3. Retrieves all records from table & display it
4. Delete any record by reading employee number from user/keyboard.
5. Update employee name by reading employee number from user
'''

import sqlite3

db = sqlite3.connect('employee.db')

cur = db.cursor()

cur.execute('''CREATE TABLE IF NOT EXISTS Employee (


employee_number INTEGER PRIMARY KEY,
employee_name TEXT,
employee_salary REAL)''')

employees = [(101, 'Ram', 50000),


(102, 'Shyam', 60000),
(103, 'Ghanshyam', 55000),
(104, 'Sita', 58000),
(105, 'Lakshman', 52000)]

cur.executemany('INSERT INTO Employee VALUES (?, ?, ?)', employees)

cur.execute('SELECT * FROM Employee')


print("Employee Records:")
for row in cur.fetchall():
print(row)

2
employee_number = int(input("Enter employee number to delete: "))
cur.execute('DELETE FROM Employee WHERE employee_number = ?',␣
↪(employee_number,))

print("Record deleted successfully.")

employee_number = int(input("Enter employee number to update name: "))


new_name = input("Enter new name: ")
cur.execute('UPDATE Employee SET employee_name = ? WHERE employee_number = ?',␣
↪(new_name, employee_number))

print("Name updated successfully.")

db.commit()
db.close()

Employee Records:
(101, 'Ram', 50000.0)
(102, 'Shyam', 60000.0)
(103, 'Ghanshyam', 55000.0)
(104, 'Sita', 58000.0)
(105, 'Lakshman', 52000.0)
Enter employee number to delete: 101
Record deleted successfully.
Enter employee number to update name: 104
Enter new name: Siya
Name updated successfully.

You might also like