CS Cum Home Test Question
CS Cum Home Test Question
A) We can write content into a text file opened using 'w' mode.
B) We can write content into a text file opened using 'w+' mode.
C) We can write content into a text file opened using 'r' mode.
D) We can write content into a text file opened using 'r+' mode.
4. Which of the following option is the correct Python statement to read and display
the first 10 characters of a text file "Notes.txt”?
A) F = open('Notes.txt') ; print(F.load(10))
B) F = open('Notes.txt') ; print(F.dump(10))
C) F = open('Notes.txt') ; print(F.read(10))
D) F = open('Notes.txt') ; print(F.write (10))
5. Which of the following is not a correct Python statement to open a text file
"Notes.txt" to write content into it?
A) F = open('Notes.txt', 'w')
B) F = open('Notes.txt., 'a')
C) F = open('Notes.txt', 'A')
D) F = open('Notes.txt', 'w+')
6. When is the finally block executed?
A) When there is no exception
B) when there is an exception
C) only if some condition that has been specified is satisfied
D) always
7. What will be the output of the following Python code?
def foo():
try:
return 1
finally:
return 2
k = foo()
print(k)
8. What happens when ‘1’ == 1 is executed?
A) We get a True
B) we get a False
C) an TypeError occurs
D) a ValueError occurs
9. Python provides a keyword _____________ which is always executed after the try and
except blocks
A)finally B)try C)catch D)except
10. Choose correct output for the following sequence of operations (* signifies top)
A)8528* B)8552* C)255* D)52*
11. Stack follow the strategy of______________
A)FIFO B)FILO C)LIFO D)random
12.______________refers to inspecting the value at the stack top without removing it
A)peek B)push D)pop D)random
13. An item sored in a stack is also known as_____________
A)item node B)item pop C)item value D)item none
14. Notation in which the operator is placed before operands is called______________
A)prefix B)infix C)postfix D)sufix
15. a+b an expression in infix to post fix is
A)ab+ B)a+b+ C)+ab D)ba+
16. HTTP stands for:
A) Outlook program
B) Web based email programs
C) Databases
D) Desktop applications
19. Stack follow the strategy of______________
A)FIFO B)FILO C)LIFO D)random
20.______________refers to inspecting the value at the stack top without removing it
A)peek B)push D)pop D)random
21. An item sored in a stack is also known as_____________
A)item node B)item pop C)item value D)item none
22. Notation in which the operator is placed before operands is called______________
A)prefix B)infix C)postfix D)sufix
23. a+b an expression in infix to post fix is
A)ab+ B)a+b+ C)+ab D)ba+
24. HTTP stands for:
E) Outlook program
F) Web based email programs
G) Databases
H) Desktop applications
27. The readlines() method returns
A) We can write content into a text file opened using 'w' mode.
B) We can write content into a text file opened using 'w+' mode.
C) We can write content into a text file opened using 'r' mode.
D) We can write content into a text file opened using 'r+' mode.
30. Which of the following option is the correct Python statement to read and display
the first 10 characters of a text file "Notes.txt”?
E) F = open('Notes.txt') ; print(F.load(10))
F) F = open('Notes.txt') ; print(F.dump(10))
G) F = open('Notes.txt') ; print(F.read(10))
H) F = open('Notes.txt') ; print(F.write (10))
31. Which of the following is not a correct Python statement to open a text file
"Notes.txt" to write content into it?
E) F = open('Notes.txt', 'w')
F) F = open('Notes.txt., 'a')
G) F = open('Notes.txt', 'A')
H) F = open('Notes.txt', 'w+')
32. When is the finally block executed?
A) When there is no exception
B) when there is an exception
C) only if some condition that has been specified is satisfied
D) always
15. What will be the output of the following Python code?
def foo():
try:
return 1
finally:
return 2
k = foo()
print(k)
33. What happens when ‘1’ == 1 is executed?
A) We get a True
B) we get a False
C) an TypeError occurs
D) a ValueError occurs
34. Python provides a keyword _____________ which is always executed after the try and
except blocks
A)finally B)try C)catch D)except
35. Choose correct output for the following sequence of operations (* signifies top)
Push(5) push(8) pop push(2) push(5) push(1)
A)8528* B)8552* C)255* D)52*
36. What is the range of frequency for radio waves?
a) 3 KHz to 1 GHz. b) 4 KHz to 1 GHz c) 5 KHz to 1 GHz d) 3 KHz to 2 GHz
37. Rearrange the following terms in increasing order of data transfer rates. Gbps,
Mbps, Tbps, Kbps, bps
a) Mbps, Gbps, Tbps, Kbps, bps b)Tbps, Mbps, Gbps, Kbps, bps
c ) Kbps, Mbps, Tbps, Gbps, bps d)Gbps, Mbps, Tbps, Kbps, bps
43. What error occurs when you execute the following Python code snippet? Apple =
mango
a) SyntaxError b) NameError c) ValueError d) TypeError
2. Statement A: Data Type defines a set of values along with well-defined operations
starting its input-output behavior
Statement B: Data Structure is a physical implementation that clearly defines a way of
storing, accessing, manipulating data.
a) Only Statement A is True b) Only Statement B is True c) Both are True d)
Both are False
44. An item sored in a stack is also known as_____________
a) item node b)item pop c)item value d)item none
45. Notation in which the operator is placed before operands is called______________
a) prefix b)infix c)postfix d)sufix
2.. Consider STACK=[23,45,67,89,51]. Write the STACK content after each operations:
1. STACK.pop( )
2. STACK.append(99)
3. STACK.append(87)
4. STACK.pop( )
3.. 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")
4.. Write the file mode that will be used for opening the following files. Also, write the
Python statements to open the following files:
a text file “example.txt” in both read and write mode.
a binary file “bfile.dat” in write mode.
a text file “try.txt” in append and read mode.
a binary file “btry.dat” in read only mode.
5. What is the use of a raise statement? Write a code to accept two numbers and
display the quotient. Appropriate exception should be raised if the user enters the
second number (denominator) as zero (0).
6.. Write a function push (student) and pop (student) to add a new student name and
remove a student name from a list student, considering them to act as PUSH and POP
operations of stack Data Structure in
a=[10,23,56,[78,10]]
b=list(a)
a[3][0]+=17
print (b)
10. Write a program to create a CSV file to store student data [Roll no, Name,
Marks].obtain data from user and write 5 records into the file.
11. Find the Error. Consider the following code, which runs correctly at times but
gives error at other times. Find the error and its reason.
Lst1 = [23, 34, 12, 77, 34, 26, 28, 93, 48, 69, 73, 23, 19, 88]
Lst2 = []
print("List1 originally is: ", Lst1)
ch = int(input("Enter 1/2/3 and \
Predict which operation was performed?"))
if ch == 1:
Lst1.append(100)
Lst2.append(100)
elif ch == 2:
print(Lst1.index(100))
print(Lst2.index(100))
elif ch == 3:
print(Lst1.pop())
print(Lst2.pop())
5MARK 10:30TO 11:30
1."Learn Together" is an educational NGO. It is setting up its new campus at Jabalpur
for its web based activities. The campus has 4 compounds as shown in the adjacent
diagram.
Main Compound 5
Resource Compound 15
Accounts Compound 20
(i) Repeater
(ii) Hub/Switch
2..If the file 'poemBTH.txt' contains the following poem (by ParamhansYoganand) :
God made the Earth;
Man made confining countries
And their fancy-frozen boundaries.
But with unfound boundLess Love
I behold the borderLand of my India
Expanding into the World.
HaiL, mother of religions, Lotus, scenic beauty, and sages!
a)my_file=open('poemBTH.txt', 'r')
my_file.read()
b)my_file=open('poemBTH.txt', 'r')
my_file.read(100)
c) my_file=open('poemBTH.txt', 'r')
my_file.readlines()