Please select a subject first
Advertisements
Advertisements
Write a function ETCount() in Python, which should read each character of a text file “TESTFILE.TXT” and then count and display the count of occurrence of alphabets E and T individually (including small cases e and t too).
Example:
If the file content is as follows:
Today is a pleasant day.
It might rain today.
It is mentioned on weather sites
The ETCount() function should display the output as:
E or e : 6
T or t : 9
Concept: Reading from a Text File in Python
Aman is a Python programmer. He has written a code and created a binary file record.dat with employeeid, ename, and salary. The file contains 10 records.
He now has to update a record based on the employee id entered by the user and update the salary. The updated record is then to be written in the file temp.dat. The records which are not to be updated also have to be written to the file temp.dat. If the employee id is not found, an appropriate message should be displayed.
As a Python expert, help him to complete the following code based on the requirement given above:
import _______ #Statement 1
def update_data():
rec={}
fin=open("record.dat","rb")
fout=open("_____________") #Statement 2
found=False
eid=int(input("Enter employee id to update their salary :: "))
while True:
try:
rec=______________ #Statement 3
if rec["Employee id"]==eid:
found=True
rec["Salary"]=int(input("Enter new salary :: "))
pickle.____________ #Statement 4
else:
pickle.dump(rec,fout)
except:
break
if found==True:
print("The salary of employee id ",eid," has
been updated.")
else:
print("No employee with such id is not found")
fin.close()
fout.close()
- Which module should be imported into the program? (Statement 1)
- Write the correct statement required to open a temporary file named temp.dat. (Statement 2)
- Which statement should Aman fill in Statement 3 to read the data from the binary file, record.dat, and in Statement 4 to write the updated data in the file, temp.dat?
Concept: The Pickle Module in Python
The syntax of seek() is:
file_object.seek(offset[,reference_point])
What is the default value of reference_point?
Concept: Setting Offsets in a File in python
Write the definition of a Python function named LongLines() which reads the contents of a text file named 'LINES.TXT' and displays those lines from the file which have at least 10 words in it. For example, if the content of 'LINES.TXT' is as follows:
Once upon a time, there was a woodcutter
He lived in a little house in a beautiful, green wood.
One day, he was merrily chopping some wood.
He saw a little girl skipping through the woods, whistling happily.
The girl was followed by a big gray wolf.
Then the function should display output as:
He lived in a little house in a beautiful, green wood.
He saw a little girl skipping through the woods, whistling happily.
Concept: Reading from a Text File in Python
Write a function count_Dwords() in Python to count the words ending with a digit in a text file "Details.txt".
Example:
If the file content is as follows:
On seat2 V1P1 will sit and
On seat1 VVIP2 will be sitting
The output will be:
The number of words ending with a digit is 4
Concept: Reading from a Text File in Python
Write one difference between CSV and text files.
Concept: Types of Files in Python
Which of the following functions changes the position of file pointer and returns its new position?
Concept: Setting Offsets in a File in python
Write a function, lenWords(STRING), that takes a string as an argument and returns a tuple containing length of each word of a string.
For example, if the string is "Come let us have some fun", the tuple will have (4, 3, 2, 4, 4, 3)
Concept: Reading from a Text File in Python
Write a function in Python to read a text file, Alpha.txt and displays those lines which begin with the word ‘You’.
Concept: Reading from a Text File in Python
Write a function, vowelCount() in Python that counts and displays the number of vowels in the text file named Poem.txt.
Concept: Reading from a Text File in Python
Consider a file, SPORT.DAT, containing records of the following structure:
[SportName, TeamName, No_Players]
Write a function, copyData(), that reads contents from the file SPORT.DAT and copies the records with Sport name as “Basket Ball” to the file named BASKET.DAT. The function should return the total number of records copied to the file BASKET.DAT.
Concept: The Pickle Module in Python
A Binary file, CINEMA.DAT has the following structure:
{MNO:[MNAME, MTYPE]}
Where
- MNO - Movie Number
- MNAME - Movie Name
- MTYPE is Movie Type
Write a user defined function, findType(mtype), that accepts mtype as parameter and displays all the records from the binary file CINEMA.DAT, that have the value of Movie Type as mtype.
Concept: The Pickle Module in Python
How are text files different from binary files?
Concept: Types of Files in Python
Explain the use of ‘Foreign Key’ in a Relational Database Management System. Give example to support your answer.
Concept: Keys in a Relational Database
Explain the concept of “Alternate Key” in a Relational Database Management System with an appropriate example.
Concept: Keys in a Relational Database
The school has asked their estate manager Mr Rahul to maintain the data of all the labs in a table LAB. Rahul has created a table and entered data from 5 labs.
| LAB NO | LAB_NAME | INCNCHARGE | CAPACITY | FLOOR |
| L001 | CHEMISTRY | Daisy | 20 | I |
| L002 | BIOLOGY | Venky | 20 | II |
| L003 | MATH | Preeti | 15 | I |
| L004 | LANGUAGE | Daisy | 36 | III |
| L005 | COMPUTER | Mary | 37 | II |
Based on the data given above answer the following questions:
(i) Identify the columns which can be considered as Candidate keys.
(ii) Write the degree and cardinality of the table.
(iii) Write the statements to:
(a) Insert a new row with appropriate data.
(b) Increase the capacity of all the labs by 10 students which are on
the 'I' Floor.
OR
(iii) Write the statements to:
(a) Add a constraints PRIMARY KEY to the column LABNO in the table.
(b) Delete the table LAB.
Concept: Keys in a Relational Database
Which of the following statements is FALSE about keys in a relational database?
Concept: Keys in a Relational Database
Give one difference between alternate key and candidate key.
Concept: Keys in a Relational Database
______ command is used to remove the primary key from a table in SQL.
Concept: SQL for Data Definition
Which of the following commands will delete the table from the MYSQL database?
Concept: SQL for Data Definition
