36,610 questions & answers

How is queue data type different from deque data type?

Fill in the blank

a) _________ is a linear list of elements in which insertion and deletion takes place from different ends.

b) Operations on a queue are performed in ______________ order

c) Insertion operation in a queue is called _______________ and deletion operation in a queue is called . $\qquad$

d) Deletion of elements is performed from ___________________ end of the queue.

e) Elements 'A','S','D' and 'F' are present in the queue, and they are deleted one at a time, ____________ is the sequence of element received.

f) _________________ is a data structure where elements can be added or removed at either end, but not in the middle.

g) A deque contains ' $z$ ',' $x$ ', 'c', 'v' and 'b' . Elements received after deletion are ' $z$ ', 'b', 'v', 'x' and 'c'. _____________ is the sequence of deletion operation performed on deque.

Compare and contrast queue with stack.

How does FIFO describe queue?

Define pickling in Python. Explain serialization and deserialization of Python object.

Write a program to enter the following records in a binary file:

Item No

integer

Item_Name

string

Qty

integer

Price

float

Number of records to be entered should be accepted from the user. Read the file to display the records in the following format:

  • Item No:

  • Item Name :

  • Quantity:

  • Price per item:

  • Amount: ( to be calculated as Price * Qty)

Write a Python program to open the file hello.txt used in question no 6 in read mode to display its contents. What will be the difference if the file was opened in write mode instead of append mode?

Write a program to accept string/sentences from the user till the user enters “END” to. Save the data in a text file and then display only those sentences which begin with an uppercase alphabet.

Write a command(s) to write the following lines to the text file named hello.txt. Assume that the file is opened in append mode.

" Welcome my class"

"It is a fun place"

"You will learn and play"

What is the difference between the following set of statements (a) and (b):

a)

P = open("practice.txt","r") 
P.read(10)

b)

with open("practice.txt", "r") as P:
    P.read()

Why is it advised to close a file after we are done with the read and write operations? What will happen if we do not close it? Will some error message be flashed?

Write the file mode that will be used for opening the following files. Also, write the Python statements to open the following files:

a) a text file "example.txt" in both read and write mode

b) a binary file "bfile.dat" in write mode

c) a text file "try.txt" in append and read mode

d) a binary file "btry.dat" in read only mode.

Write the use and syntax for the following methods:

a) open()

b) read()

c) seek()

d) dump()

Differentiate between:

a) text file and binary file

b) readline() and readlines()

c) write() and writelines()

You have learnt how to use math module in Class XI. Write a code where you use the wrong number of arguments for a method (say sqrt() or pow()). Use the exception handling process to catch the ValueError exception.

What is the use of finally clause? Use finally clause in the problem given in Question No. 7.

Consider the code given below and fill in the blanks.

print (" Learning Exceptions...")
try:
    num1= int(input ("Enter the first number"))
    num2=int(input("Enter the second number"))
    quotient=(num1/num2)
    print ("Both the numbers entered were correct")
except _______________: # to enter only integers
    print (" Please enter only numbers")
except _____________: # Denominator should not be zero
    print(" Number 2 should not be zero")
else:
    print(" Great .. you are a good programmer")
________________: # to be executed at the end
    print(" JOB OVER... GO GET SOME REST")

Define the following:

a) Exception Handling

b) Throwing an exception

c) Catching an exception

Use assert statement in Question No. 3 to test the division expression in the program.

Explain catching exceptions using try and except block.