Write a method in Python to read lines from a text file DIARY.TXT

Subject

Computer and Communication Technology

Class

CBSE Class 12

Pre Boards

Practice to excel and get familiar with the paper pattern and the type of questions. Check you answers with answer keys provided.

Sample Papers

Download the PDF Sample Papers Free for off line practice and view the Solutions online.
Advertisement

 Multiple Choice QuestionsShort Answer Type

11.

Define a class RING in Python with following specifications

Instance Attributes
- RingID 		# Numeric value with a default value 101
- Radius 		# Numeric value with a default value 10
- Area 			# Numeric value
Methods:
- AreaCal() 	# Method to calculate Area as
				# 3.14*Radius*Radius
- NewRing() 	# Method to allow user to enter values of
				# RingID and Radius. It should also
				# Call AreaCal Method
- ViewRing() 	# Method to display all the Attributes 4
126 Views

12.

Differentiate between static and dynamic binding in Python? Give the suitable example of each.

95 Views

13.

Write two methods in Python using the concept of Function Overloading (Polymorphism) to perform the following operations:
(i) A function having one argument as side, to calculate Area of Square as side*side
(ii) A function having two arguments as Length and Breadth, to calculate Area of Rectangle as Length*Breadth.

85 Views

14.

What will be the status of the following list after the First, Second and Third pass of the bubble sort method used for arranging the following elements in descending order ?
Note: Show the status of all the elements after each pass very clearly underlining the changes.
152, 104, -100, 604, 190, 204

90 Views

Advertisement
15.

Write the definition of a method OddSum(NUMBERS) to add those values in the list of NUMBERS, which are odd. 

82 Views

16.

Write Addnew(Book) and Remove(Book) methods in Python to Add a new Book and Remove a Book from a List of Books, considering them to act as PUSH and POP operations of the data structure Stack.

92 Views

17.

Write the definition of a Method AFIND(CITIES) to display all the city names from a list of CITIES, which are starting with alphabet A.

For example:
If the list CITIES contains ['AHMEDABAD','CHENNAI','NEW DELHI','AMRITSAR','AGRA']

The following should get displayed
AHMEDABAD
AMRITSAR
AGRA

71 Views

18.

Evaluate the following Postfix notation of expression:
2,3,*,24,2,6,+,/,-

69 Views

Advertisement
19.

Differentiate between file modes r+ and w+ with respect to Python.

74 Views

Advertisement

20.

Write a method in Python to read lines from a text file DIARY.TXT, and display those lines, which are starting with an alphabet ‘P’.


def display():
	file=open('DIARY.TXT','r')
	line=file.readline()
	while line:
		if line[0]=='P' :
			print line
			line=file.readline()
	file.close() #IGNORE
87 Views

Advertisement
Advertisement