Assignment
Assignment
txt`**:
```python
def count_words_with_vowel():
text = file.read()
words = text.split()
vowel_words = [word for word in words if any(vowel in word.lower() for vowel in 'aeiou')]
print(vowel_words)
```
```python
def copy_lines_starting_with_A():
if line.startswith("A"):
target.write(line)
```
```python
def count_the_and_an():
text = file.read().lower()
the_count = text.split().count("the")
an_count = text.split().count("an")
```
4. **Student Data in `student.txt` with Update Function**:
```python
def create_student_file():
students = [
file.write(f"{student['roll']},{student['name']},{student['city']},{student['phone']}\n")
found = False
lines = []
lines = file.readlines()
parts = line.strip().split(',')
if parts[1] == name:
parts[3] = new_phone
found = True
file.write(','.join(parts) + "\n")
if not found:
```
```python
```
```python
import pickle
def CreateFile():
pickle.dump(record, file)
def CountRect(author):
count = 0
while True:
try:
record = pickle.load(file)
if record["Author"] == author:
count += 1
except EOFError:
break
return count
def Display():
count = 0
while True:
try:
record = pickle.load(file)
count += 1
except EOFError:
break
```
```python
def update_mobile_numbers():
import pickle
records = []
try:
while True:
record = pickle.load(file)
if record["mobile_no"].startswith("8"):
records.append(record)
except EOFError:
pass
pickle.dump(record, file)
```
```python
def write_data():
import pickle
students = [{"rollno": 1, "name": "John", "M_Physics": 85, "M_Chemistry": 90, "M_Maths": 95}]
for student in students:
pickle.dump(student, file)
```
```python
import csv
def write_books_to_csv():
writer = csv.writer(file)
while True:
if bno.lower() == 'n':
break
```
```python
def read_books_from_csv():
import csv
next(reader)
max_quantity = 0
max_book = None
quantity = int(row[4])
max_quantity = quantity
max_book = row
```
===========
=================
```python
def MakePush(package):
stack.append(package)
def MakePop():
if len(stack) > 0:
removed_package = stack.pop()
print(f"Package '{removed_package}' removed from the stack.")
return removed_package
else:
return None
```
```python
def PUSH(Arr):
if number % 5 == 0:
stack.append(number)
if len(stack) > 0:
else:
```
```python
def POP(Arr):
if len(Arr) > 0:
removed_value = Arr.pop()
return removed_value
else:
return None
```
==========
```
Each code block includes a connection setup. Make sure to replace `'your_username'`,
`'your_password'`, `'localhost'`, and `'record'` (or `'school'`) with your actual database credentials.
### 1. Retrieve Students with Marks > 95% in Physics and Chemistry
```python
import mysql.connector
def fetch_high_scorers():
conn = mysql.connector.connect(
host='localhost',
user='your_username',
password='your_password',
database='record'
cursor = conn.cursor()
query = """
"""
cursor.execute(query)
result = cursor.fetchall()
cursor.close()
conn.close()
fetch_high_scorers()
```
### 2. Retrieve One Record at a Time from `Employee` Table for Employees Living in Delhi
```python
import mysql.connector
def fetch_employees_in_delhi():
conn = mysql.connector.connect(
host='localhost',
user='your_username',
password='your_password',
database='record'
cursor = conn.cursor()
query = """
"""
cursor.execute(query)
row = cursor.fetchone()
row = cursor.fetchone()
cursor.close()
conn.close()
fetch_employees_in_delhi()
```
```python
import mysql.connector
def insert_doctor_record():
conn = mysql.connector.connect(
host='localhost',
user='your_username',
password='your_password',
database='record'
cursor = conn.cursor()
query = """
cursor.execute(query, data)
conn.commit()
cursor.close()
conn.close()
insert_doctor_record()
```
### 4. Update Salary by 10% for Employees Whose Name Starts with 'A' and Has 'h' as the Third
Letter
```python
import mysql.connector
def update_salary():
conn = mysql.connector.connect(
host='localhost',
user='your_username',
password='your_password',
database='record'
cursor = conn.cursor()
query = """
UPDATE Employee
SET Salary = Salary * 1.10
"""
cursor.execute(query)
conn.commit()
cursor.close()
conn.close()
update_salary()
```
### 5. Delete a Record from `student` Table in `school` Database Where Name = 'Mayur'
```python
import mysql.connector
def delete_student_record():
conn = mysql.connector.connect(
host='localhost',
user='your_username',
password='your_password',
database='school'
cursor = conn.cursor()
query = """
"""
cursor.execute(query)
conn.commit()
cursor.close()
conn.close()
delete_student_record()
```