[go: up one dir, main page]

0% found this document useful (0 votes)
25 views4 pages

CT 3 CS

Uploaded by

sanjay.sb0112
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)
25 views4 pages

CT 3 CS

Uploaded by

sanjay.sb0112
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
You are on page 1/ 4

I.

ANSWER THE FOLLOWING:


1. Find the errors in following function definitions.
def main() def compute ( ):
print(“Hello”) print(x*x)
2. (i) What is the area of memory called, which stores the
parameters and local variables of a function call ?
(ii) Write the output of the given code:

3. Which of the following function definition header is


wrong?
a. def sum(n1, n2, n = 3):
b. def scan(p1, p2 = 4, p3 = 5):
c. def div(p1=4, p2, p3):
d. def mul(p1, n1, m1):
4. A function may return multiple values using _______.
5. A stack is one of the following types of data structure.
a. dynamic b. linear c. circular d. hierarchy
6. You can replace any element position in the stack [True/False]
7. In k = open(“data.txt”,”w”), k refers to _________.
8. Name the function that flushes the data before closing the file?
9. Name the file type that can be opened with notepad as well as MS Excel.
10. Every file has its own identity associated with it. Which is known as ________?

II. ANSWER THE FOLLOWING QUESTIONS:

11. Find the error in the given program:

OR
12. Find the output of the following code:
(i) (ii)

13. Find the output of the following:

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:

20. Write the output of the given code:

def change(i = 1, j = 2): def change(one, *two): def display(b, n):


i=i+j print(type(two)) while n > 0:
j=j+1 change(1,2,3,4) print(b,end="")
print(j+3,i+2) n=n-1
change(j = 1, i = 2) display('z',3)

21. Write the output of the following code:

NList = [60, 32, 13, 'hello' ]


print (NList[1], NList[-2])
NList.append( 15 )
print(len (NList))
print( len(NList[3]))
NList.pop(3)
NList.sort()
NList.insert(2, [14, 15])
NList[3] += NList[4]
NList[3] += NList[2][1]
print (NList[3])
NList.pop()
NList[2].remove(14)
print (NList)
OR

(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:

Friends are crazy, Friends are naughty !


Friends are honest, Friends are best !
Friends are like keygen, friends are like license key !
We are nothing without friends, Life is not possible without friends !
f = open("friends.txt")
l = f.readline()
l2 = f.readline(18)
ch3=f.read(10)
print(l2)
print(ch3)
print(f.readline())
f.close()

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?

You might also like