1. Answer the below ASSERTION(A) AND REASONING(R) based questions. Mark the correct choice as :
(i)Both A and R are true and R is the correct explanation for A.
(ii)Both A and R are true and R is not the correct explanation for R.
(iii)A is true but R is false.
(iv)A is false but R is true.
a) (A): The close() method is used to close the file.
(R): While closing a file, the system frees up all the resources like processor and memory allocated to it.
b)(A): To preserve the data for future purpose in Python is called pickling.
(R): Unpickling is a technique that returns the byte stream produced by pickling back into Python objects.
c) A): CSV stands for Comma separated values.
(R): CSV files are common file format for transferring and storing data
d)(A): Access mode ‘a’ opens the file for appending.
(R): So it writes text only in the end of the file, but if we use seek(0), it will change the file pointer the beginning of the file and write the text there.
e) (A): DDL commands are used to manipulate data in the table.
(R): INSERT and UPDATE are examples of DDL commands.
2) Below two questions are based on sample.txt which contains :
Apple
Banana
Cherry
Dragonfruit
Predict the output of :
i) f = open("sample.txt", "r")
f.read()
print(f.read())
f.close()
ii) f = open("sample.txt", "r")
print(f.readline(2))
print(f.readline())
print(f.read())
f.close()
3. A table STUDENT has 6 rows and 4 columns.What is the degree and cardinality of the table?
4) def update_data(X, Y):
X.append(30)
Y = Y + [30]
print(X, Y, sep="*")
List1 = [10, 20]
Li st2 = [10, 20]
update_data(List1, List2)
print(List1, List2, sep="#")
5)Observe the following Python function definition and call:
def Assign(P, Q, R=100):
print(P, Q, R)
Assign(10, 20, P=30)
What will be the outcome of executing this code?
6)Differentiate between :
7) a) Write a function addrec() in Python to add 1 new record at the end of the binary file “Student.dat”, assuming that the binary file contains the following structure : {Roll:<int>,sname:<str>,score:<int>}
b) Increase the score of all the students who scored between 30-34 to 35.
c) Search for a certain roll no , and display the score
d) Display all the records
8) Define a function remove_newline() which will remove new line from sample.txt:
9) Write python code that works on text files :
a) Write a function entry() that accepts10 lines on the uses of python and writes it into data.txt.
b) Write a function summary() that reads data.txt and:
>Counts the number of words that start with ‘re’
>Displays the lines that end with tion (remove the fullstop or question mark before you check)
>Prints all lines that contain the word “python”
>Replace every occurrence of red by RED.
10) A binary file (weather.dat) which contains each record as a list, as given : [“date”,lowest temperature,highest temperature] eg. [“26-08-2023”,30.0,40.0]
a) Update all the records to contain a 4th field – average temperature.
b) Search for a particular date and display its average temperature, If the record is not found, display ‘Record Not Found’.
c) Display all the records and the lowest and highest temperatures recorded
11) The following is a snapshot of customer.csv.
a) Accept records until the user wants to stop.
b) Display all the records in a tabular format. Also the total amount of sales.
c) Search for a serial number and display the corresponding Amount
d) Update all those from Bangalore to Bengaluru.
e) Accept a name delete a row from the above csv file if the record exists.
12. Your parent wishes to maintain their monthly expenses. Write the following python functions:
a) accept () to prompt the user to enter expense details and store them into the file ‘Expense_July.csv’ with appropriate headers :
b) total() to display all the records from Expense_July.csv and also print the total expense for the month.
c) update() to change the school fees to 8000
13)Given the list:
sales = [["Tom", 12000], ["Ava", 8000], ["Kia", 15000], ["Max", 9000]]
Write Python code to:
a) Push the names of salespersons into a stack only if their sales are above 10,000.
b) Display the names from the stack without deleting the elements.
c) Pop the topmost element from the stack
14) Write a SQL query to CREATE a table Faculty with columns:
Fid (INT, PRIMARY KEY)
Name (VARCHAR(30))
Department (VARCHAR(20))
Salary (DECIMAL(8,2))
a) A a new column Email (VARCHAR(40))
b) Change Department column to DeptName
c) Change Name column data type to VARCHAR(20)
d) Remove the column Salary
e)Remove the primary key
f)Make Fid,Name as the new primary key
g)Why is it important to define constraints in a table?
15) Identify and correct the errors in the following SQL statements:
a) CREATE TABLE Emp (ID int, Name varchar, Salary float);
b) ALTER TABLE Emp DROP Salary WHERE ID=3;
c) ALTER Emp RENAME COLUMN Name TO EmpName;
16) Answer the questions that follow the table given below:
a) What is the full form of RDBMS? Give one advantage of RDBMS of CSV file
b) What is the cardinality of the above table ? What is the degree of the above table ?
c) Which is/are the alternate/primary/candidate key/keys in the above table?
d) Identify the below commands as either DDL, or DML. :
INSERT, ALTER, DROP, CREATE, UPDATE, DELETE
17) Answer briefly :
a)referential integrity.
b)primary key and give one example.
c)secondary key with example
d)various constraints
e)what is the various referential actions -set null, no action , cascade and restrict?
f) one difference between CSV files and tables in MySQL.
18) What does cascade do in the below context ?
CREATE TABLE EMPLOYEE (
EmpID INT PRIMARY KEY,
EmpName VARCHAR(30),
DeptID INT,
FOREIGN KEY (DeptID) REFERENCES DEPARTMENT(DeptID) ON DELETE CASCADE
);
No comments:
Post a Comment