0% found this document useful (0 votes)
377 views3 pages

QASW2

The function display(eno) opens an employee data file in binary read mode, initializes a total sum variable to 0, reads records from the file using a while loop, and if the employee number from the record matches the parameter eno it adds the salary field from the record to the total sum. It catches any exceptions, closes the file, and prints the total sum. When this function is called with parameter 103, it outputs 190000. The appropriate jump statement to obtain this output is to print the salary field from the matching record.

Uploaded by

praveen.aicp
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
377 views3 pages

QASW2

The function display(eno) opens an employee data file in binary read mode, initializes a total sum variable to 0, reads records from the file using a while loop, and if the employee number from the record matches the parameter eno it adds the salary field from the record to the total sum. It catches any exceptions, closes the file, and prints the total sum. When this function is called with parameter 103, it outputs 190000. The appropriate jump statement to obtain this output is to print the salary field from the matching record.

Uploaded by

praveen.aicp
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

def display(eno):

f=open("employee.dat","rb")
totSum=0
try:
while True:
R=pickle.load(f)
if R[0]==eno:
__________ #Line1
totSum=totSum+R[2]
except:
f.close()
print(totSum)
When the above mentioned function, display (103) is executed, the output displayed is
190000. Write appropriate jump statement from the following to obtain the above
output.

76. Suppose content of 'Myfile.txt' is:


Honesty is the best policy.
What will be the output of the following code?
myfile = open("Myfile.txt")
x = myfile.read()
print(len(x))
myfile.close()

77. Suppose content of 'Myfile.txt' is


Culture is the widening of the mind and of the spirit.
What will be the output of the following code?

myfile = open("Myfile.txt")
x = myfile.read()
y = x.count('the')
print(y)
myfile.close()

78. Suppose content of 'Myfile.txt' is

Humpty Dumpty sat on a wall


Humpty Dumpty had a great fall

96 | P a g e
All the king's horses and all the king's men
Couldn't put Humpty together again

What will be the output of the following code?


myfile = open("Myfile.txt")
record = myfile.read().split()
print(len(record))
myfile.close()

79. Suppose content of 'Myfile.txt' is

Ek Bharat Shreshtha Bharat


What will be the output of the following code?

80. Consider the following directory structure.

Suppose root directory (School) and present working directory are the same. What will
be the absolute path of the file Syllabus.jpg?
a) School/syllabus.jpg
b) School/Academics/syllabus.jpg
c) School/Academics/../syllabus.jpg
d) School/Examination/syllabus.jpg

81. A binary file “STUDENT.DAT” has structure (admission_number, Name, Percentage).


Write a function countrec() in Python that would read contents of the file “STUDENT.DAT”
and display the details of those students whose percentage is above 75. Also display
number of students scoring above 75%

82. A binary file “Book.dat” has structure [BookNo, Book_Name, Author, Price]. i. Write a
user defined function CreateFile() to input data for a record and add to Book.dat . ii. Write

97 | P a g e
a function CountRec(Author) in Python which accepts the Author name as parameter and
count and return number of books by the given Author are stored in the binary file
“Book.dat”

83. Write a function in Python that counts the number of “Me” or “My” words present in a
text file “STORY.TXT”. If the “STORY.TXT” contents are as follows:
My first book was
Me and My Family.
It gave me chance to be
Known to the world.

The output of the function should be: Count of Me/My in file: 4

84. Write a function AMCount() in Python, which should read each character of a text file
STORY.TXT, should count and display the occurance of alphabets A and M (including small
cases a and m too).
Example: If the file content is as follows:

Updated information As simplified by official websites.


The EUCount() function should display the output as:
A or a:4
M or m :2

85. Write a function in python to count the number of lines in a text file ‘STORY.TXT’ which is
starting with an alphabet ‘A’ .

86. Write a method/function DISPLAYWORDS() in python to read lines from a text file
STORY.TXT, and display those words, which are less than 4 characters.

87. Write the definition of a function Count_Line() in Python, which should read each line of
a text file "SHIVAJI.TXT" and count total number of lines present in text file. For example,
if the content of the file "SHIVAJI.TXT" is as follows:
Shivaji was born in the family of Bhonsle.
He was devoted to his mother Jijabai.
India at that time was under Muslim rule.
The function should read the file content and display the output as follows:

Total number of lines: 3

88. A binary file "PLANTS.dat" has structure (ID, NAME, PRICE).

Write the definition of a function WRITEREC () in Python, to input data for records from
the user and write them to the file PLANTS.dat.
Write the definition of a function SHOWHIGH () in Python, which reads the records of
PLANTS. dat and displays those records for which the PRICE is more than 500.

89. Write the definition of a Python function named LongLines ( ) which reads the contents

98 | P a g e

You might also like