Board Practical Solutions
Board Practical Solutions
1. Read a text file line by line and display each word separated by a #:
words = line.split()
print("#".join(words))
vowels = "aeiouAEIOU"
text = file.read()
consonant_count = sum(1 for char in text if char.isalpha() and char not in vowels)
3. Remove lines containing the character 'a' and write to another file:
outfile.write(line)
Board Practical Solutions
import pickle
pickle.dump(data, file)
data = pickle.load(file)
data = pickle.load(file)
data[roll_number] = new_marks
pickle.dump(data, file)
import random
stack = []
stack.append(10)
stack.append(20)
stack.pop() # Removes 20
import csv
writer = csv.writer(file)
writer.writerow(["user1", "pass1"])
writer.writerow(["user2", "pass2"])
reader = csv.reader(file)
if row[0] == search_user:
print(f"Password: {row[1]}")
SQL Solutions
name VARCHAR(50),
marks INT
);
INSERT INTO students VALUES (101, 'John', 85), (102, 'Alice', 90);
2. ALTER table:
3. UPDATE table:
4. ORDER BY clause:
Board Practical Solutions
5. DELETE rows:
import sqlite3
connection = sqlite3.connect("school.db")
cursor = connection.cursor()
cursor.execute("CREATE TABLE IF NOT EXISTS students (roll_number INT, name TEXT, marks
INT)")
cursor.execute("INSERT INTO students VALUES (101, 'John', 85), (102, 'Alice', 90)")
print(cursor.fetchall())
connection.commit()
Board Practical Solutions
connection.close()