CT 3 CS
CT 3 CS
OR
12. Find the output of the following code:
(i) (ii)
def div5(n):
if n%5==0:
return n*5
else:
return n+5
def output(m=5):
for i in range(0,m):
print(div5(i),'@',end=" ")
print('\n')
output(7)
output()
14. (i) Write a python function named is_underflow() to check a stack is an underflow.
(ii) Write a function to push an element in to the stack.
15. Write the difference between text file and binary file.
16. Explain open( ) function with its syntax in detail.
17. Write a python program to create and read the city.txt file in one go and print the contents on
the output screen.
III. ANSWER THE FOLLOWING QUESTIONS:
18. Write a program to have following functions.
(i) A function that takes a number as argument and calculates cube for it. The function does not
return a value. If there is no value passed to the function in function call, the function should calculate cube
of 2.
(ii) A function that takes two char arguments and returns True if both the arguments are equal
otherwise False.
Test both these functions by giving appropriate function call statements.
19. Find the output of the following code:
(i) Convert the given infix expression to postfix expression showing the stack contents for each step of
conversion. ( P +( ( ( Q – R ) * S ) / T ) ).
(ii) Evaluate the given postfix expression. 23, 8, 3, -, /, 6, *, 10, +.
22. Consider following lines for the file friends.txt and predict the output:
23. (i)Write a function count_lines() to count and display the total number of lines from the file. Consider above
file – friends.txt.
(ii) a. How to read data from binary file? b. How to write data from binary file?
IV.ANSWER ALL THE QUESTIONS:
24. (i) Write the difference between parameter and argument.
(iii) Write the output of the given code
25. (i) A binary file “Book.dat” has structure [BookNo, Book_Name, Author, Price]. Write a user defined
function CreateFile() to input data for a record and add to Book.dat .
(ii) Fill in the blank:
import pickle
f=open("data.dat",'rb')
d=_____________________.load(f)
f.close()
(iii) Which of the following error is returned when we try to open a file in write mode which does not exist?