0% found this document useful (0 votes)
87 views3 pages

CS Model Test

The document contains 20 multiple choice questions related to computer science and Python programming. Some questions test Python syntax and semantics, such as valid identifiers, operators, data types, and built-in functions. Other questions involve analyzing and predicting the output of short Python code snippets. The last question asks how to ensure a variable has an integer value after a division operation in Python.

Uploaded by

DJ Ghostmallow
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
87 views3 pages

CS Model Test

The document contains 20 multiple choice questions related to computer science and Python programming. Some questions test Python syntax and semantics, such as valid identifiers, operators, data types, and built-in functions. Other questions involve analyzing and predicting the output of short Python code snippets. The last question asks how to ensure a variable has an integer value after a division operation in Python.

Uploaded by

DJ Ghostmallow
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

COMPUTER SCIENCE (TEST NO.

2)

1. Find the invalid identifier from the following

a) MyName b) True c) 2ndName d) My_Name

2. What is the output of the following?


x = 'abcd'
for i in range(len(x)):
print(x) x = 'a'
a) a b) abcd abcd abcd abcd c) a a a a d) none of the mentioned.
3. Identify the valid arithmetic operator in Python from the following.
a) ? b) < c) ** d) and
4. Suppose a tuple T is declared as T = (10, 12, 43, 39), which of the following is incorrect?

a) print(T[1]) b) T[2] = -29 c) print(max(T)) d) print(len(T))

5. Write a statement in Python to declare a dictionary whose keys are 1, 2, 3 and values are
Monday, Tuesday and Wednesday respectively.
6. What is the output of the following?
x = "abcdef"
i = "i"
while i in x:
print(i, end=" ")

a) no output b) i i i i i i … c) a b c d e f d) abcdef

7. What is the output of the following?


i=5
while True:
if i%0O11 == 0:
break

print(i)

i += 1

a) 5 6 7 8 9 10 b) 5 6 7 8 c) 5 6 d) error

8. Ranjan Kumar of class 12 is writing a program to create a CSV file “user.csv” which will contain
user name and password for some entries. He has written the following code. As a programmer,
help him to successfully execute the given task.
import _____________ # Line 1
def addCsvFile(UserName,PassWord): # to write / add data into the CSV file
f=open(' user.csv','________') # Line 2
newFileWriter = csv.writer(f)
newFileWriter.writerow([UserName,PassWord])
f.close() #csv file reading code

def readCsvFile(): # to read data from CSV file


with open(' user.csv','r') as newFile:
newFileReader = csv._________(newFile) # Line 3
for row in newFileReader:
print (row[0],row[1])
newFile.______________ # Line 4
addCsvFile(“Arjun”,”123@456”)
addCsvFile(“Arunima”,”aru@nima”)
addCsvFile(“Frieda”,”myname@FRD”)
readCsvFile() #Line 5
9. Evaluate the following expressions:

a) 6 * 3 + 4**2 // 5 – 8 b) 10 > 5 and 7 > 12 or not 18 > 3

10. What possible outputs(s) are expected to be displayed on screen at the time of execution of the
program from the following code? Also specify the maximum values that can be assigned to
each of the variables Lower and Upper.
import random
AR=[20,30,40,50,60,70];
Lower =random.randint(1,3)
Upper =random.randint(2,4)
for K in range(Lower, Upper +1):
print (AR[K],end=”#“)

(i) 10#40#70# (ii) 30#40#50# (iii) 50#60#70# (iv) 40#50#70#

11. Find and write the output of the following Python code:
def Display(str):
m=""
for i in range(0,len(str)):
if(str[i].isupper()):
m=m+str[i].lower()
elif str[i].islower():
m=m+str[i].upper()
else:
if i%2==0:
m=m+str[i-1]

else:
m=m+"#"

print(m)

Display('[email protected]')

12. What is the output of the following code?


>>> a=(2,3,4)
>>> sum(a,3)
a) Too many arguments for sum() method
b) The method sum() doesn’t exist for tuples
c) 12
d) 9
13. What is the output of the following code?
>>> a=(1,2,3,4)
>>> del(a[2])

a) Now, a=(1,2,4) b) Now, a=(1,3,4) c) Now a=(3,4) d) Error as tuple is immutable

14. What is the output of the following piece of code when executed in Python shell?
>>> a=("Check")*3
>>> a
a) (‘Check’,’Check’,’Check’) b) * Operator not valid for tuples
c) (‘CheckCheckCheck’) d) Syntax error
15. What is the output of the following?
print("xyyzxyzxzxyy".count('yy', 2))

a) 2 b) 0 c) 1 d) none of the mentioned

16. What is the output of the following?


print("xyyzxyzxzxyy".count('xyy', 0, 100))

a) 2 b) 0 c) 1 d) erro

17. print(0xA + 0xB + 0xC) : a) 0xA0xB0xC b) Error c) 0x22 d) 33


18. What does ~~~~~~5 evaluate to? a) +5 b) -11 c) +11 d) -5
19. What is the output of print 0.1 + 0.2 == 0.3? a) True b) False c) Machine dependent d) Error
20. In python we do not specify types,it is directly interpreted by the compiler, so consider the
following operation to be performed.
>>>x = 13 ? 2
objective is to make sure x has a integer value, select all that apply (python 3.xx)

a) x = 13 // 2 b) x = int(13 / 2) c) x = 13 % 2 d) All of the mentioned

You might also like