Class 12 Practical With Answers
Class 12 Practical With Answers
To design a function in Python to read a text file and count the vowels, consonants, uppercase, and lowercase characters, you can define a function that opens the file for reading, iterates over each character, and uses Python string methods like isupper(), islower(), and isalpha(). Initialize counters for each category and increment them based on the conditions when reading each character from the file.
To write a Python program to display prime numbers from 2 to a given number N using a user-defined function, you can define a function CheckPrime(N) that iterates through each number from 2 to N. For each number, check if it is prime by testing divisibility from 2 up to the square root of the number. If a number is only divisible by 1 and itself, it is a prime number.
To manipulate a 'Student' table in SQL by adding a new column and modifying the fees for a specific student, you can use the following queries: To add a new column, use `ALTER TABLE Student ADD TotalFees Float(10,2);`. To modify the fees for a student with a specific adno (e.g., 222), use `UPDATE Student SET Fees = Fees + 100 WHERE Adno = 222;`.
To update a binary file with student records in Python, open the file in read+write binary mode. Use pickle module to read records, identify the target record through a search (e.g., based on roll number), update the relevant fields, then write back the changes. Ensure file pointers are correctly managed for read/write operations..
To display student details sorted in descending order by fees, use `SELECT * FROM student ORDER BY Fees DESC;`. To compute the sum and average of student fees, use `SELECT SUM(Fees), AVG(Fees) FROM Student;`.
To delete a student's record by admission number, use `DELETE FROM Student WHERE Adno = 444;`. This operation removes all data associated with that admission number, which could affect database integrity by removing links to related data, potentially leading to data anomalies unless integrity constraints or cascading deletes are managed properly..
To list all unique classes in a student table, use `SELECT DISTINCT Class FROM Student;`. This information is useful for generating reports, allocating resources, or identifying specific class cohorts for administrative tasks..
To modify a SQL table structure to change the data type of a column, use an ALTER TABLE statement. For instance, to adjust the data type of a fees column in a student table, execute `ALTER TABLE Student MODIFY Fees Float(12,2);`. This change might be needed to increase precision for financial data.
To configure a stack in Python using a list, implement methods to push items to the end of the list and pop items from the end. This mimics the last-in, first-out (LIFO) property of stacks. Unlike traditional stacks that might use linked lists for dynamic memory usage, Python's list-based stack solutions are simpler and leverage built-in list methods like append() and pop().
To securely create a CSV file in Python to store user IDs and passwords, use the csv module to write the rows. Ensure passwords are hashed for security. Implement a function to look up a user ID and verify the password hash against stored values, avoiding storing plaintext passwords for security compliance..