Docsity

python important questions, Exercises of Computer science

Toggle sidebar
bg1
OXALISS INTERNATIONAL SCHOOL (CBSE), THATCHUR.
Computer Science (083)
CYCLIC TEST – I (2024-25)
Class: XII Max. Marks: 70
Date : 10.10.2024 Time : 3 Hrs.
General Instructions:
This question paper contains 37 questions.
All questions are compulsory. However, internal choices have been provided in some
questions. Attempt only one of the choices in such questions
The paper is divided into 5 Sections- A, B, C, D and E.
Section A consists of 21 questions (1 to 21). Each question carries 1 Mark.
Section B consists of 7 questions (22 to 28). Each question carries 2 Marks.
Section C consists of 3 questions (29 to 31). Each question carries 3 Marks.
Section D consists of 4 questions (32 to 35). Each question carries 4 Marks.
Section E consists of 2 questions (36 to 37). Each question carries 5 Marks.
All programming questions are to be answered using Python Language only.
In case of MCQ, text of the correct answer should also be written.
SECTION – A
Q No. Section-A (21 x 1 = 21 Marks) Marks
1. Which is valid keyword?
a. Int b. WHILE c.While d.if
1
2. Which of the following statement(s) would give an error after executing the
following code?
print(9/2) # Statement-1
print(9//2) # Statement-2
print(9%%2) # Statement-3
print(9%2) # Statement-4
(a) Statement-1 (b) Statement-2 (c) Statement-3 (d) Statement-4
1
3. State True or False
“The characters of string will have two-way indexing.”
1
4. What will be the output after the following statements?
x = 27
y = 9
while x < 30 and y < 15:
x = x + 1
y = y + 1
print(x,y)
a) 26 11 b) 25 11 c) 30 12 d) 26 10
1
5. State True or False
“variable declaration is implicit in Python”
1
6. Which of the following is an invalid datatypes in Python?
(a) Set (b) None (c) Integer (d) Real
1
7. Which of the following is a mutable datatype in Python?
(a) String (b) List (c)Integer (d) Tuple
1
8. Select the correct output of the code: Str=“Computer” Str=Str[-4:] print(Str*2)
a. uter b. uterretu c. uteruter d. None of these
1
9. What will be the output of the following code?
D1={1: “One”,2: “Two”, 3: “C”}
D2={4: “Four”,5: “Five”}
1
pf3
pf4
pf5
pf8

Partial preview of the text

Download python important questions and more Exercises Computer science in PDF only on Docsity!

OXALISS INTERNATIONAL SCHOOL (CBSE), THATCHUR.

Computer Science (083)

CYCLIC TEST – I (2024-25)

Class: XII Max. Marks: 70

Date : 10.10.2024 Time : 3 Hrs.

General Instructions:  This question paper contains 37 questions.  All questions are compulsory. However, internal choices have been provided in some questions. Attempt only one of the choices in such questions  The paper is divided into 5 Sections- A, B, C, D and E.  Section A consists of 21 questions (1 to 21). Each question carries 1 Mark.  Section B consists of 7 questions (22 to 28). Each question carries 2 Marks.  Section C consists of 3 questions (29 to 31). Each question carries 3 Marks.  Section D consists of 4 questions (32 to 35). Each question carries 4 Marks.  Section E consists of 2 questions (36 to 37). Each question carries 5 Marks.  All programming questions are to be answered using Python Language only.  In case of MCQ, text of the correct answer should also be written. SECTION – A Q No. Section-A (21 x 1 = 21 Marks) Marks

  1. Which is valid keyword? a. Int b. WHILE c.While d.if
  1. Which of the following statement(s) would give an error after executing the following code? print(9/2) # Statement- print(9//2) # Statement- print(9%%2) # Statement- print(9%2) # Statement- (a) Statement-1 (b) Statement-2 (c) Statement-3 (d) Statement-
  1. State True or False “The characters of string will have two-way indexing.”
  1. What will be the output after the following statements? x = 27 y = 9 while x < 30 and y < 15: x = x + 1 y = y + 1 print(x,y) a) 26 11 b) 25 11 c) 30 12 d) 26 10
  1. State True or False “variable declaration is implicit in Python”
  1. Which of the following is an invalid datatypes in Python? (a) Set (b) None (c) Integer (d) Real
  1. Which of the following is a mutable datatype in Python? (a) String (b) List (c)Integer (d) Tuple
  1. Select the correct output of the code: Str=“Computer” Str=Str[-4:] print(Str*2) a. uter b. uterretu c. uteruter d. None of these
  1. What will be the output of the following code? D1={1: “One”,2: “Two”, 3: “C”} D2={4: “Four”,5: “Five”}

D1.update(D2) print (D1) a) {4:’Four’,5: ‘Five’} b) Method update() doesn’t exist for dictionary c) {1: “One”,2: “Two”, 3: “C”} d) {1: “One”,2: “Two”, 3: “C”,4: ‘Four’,5: ‘Five’}

  1. Select the correct output of the following code : s=“I#N#F#O#R#M#A#T#I#C#S” L=list(s.split(‘#’)) print(L) a) [I#N#F#O#R#M#A#T#I#C#S] b) [‘I’, ‘N’, ‘F’, ‘O’, ‘R’, ‘M’, ‘A’, ‘T’, ‘I’, ‘C’, ‘S’] c) [‘I N F O R M A T I C S’] d) [‘INFORMATICS’]
  1. Which of the following statement(s) would give an error after executing the following code? str= “Python Programming” #statement 1 x= ‘2’ #statement 2 print(str2) #statement 3 print(strx) #statement 4 a) statement 1 b) statement 2 c) statement 3 d) statement 4
  1. Find the operator which cannot be used with a string in Python from the following:- a) // b) * c) + d) in
  1. Select the correct output of the code: Str = "OXALISS INTERNATIONAL CBSE SCHOOL THATCHUR " Str = Str.split() NewStr = Str[0] + "#" + Str[1] + "#" + Str[4] print (NewStr) a) OXALISS#INTERNATIONAL#CBSE# SCHOOL b) OXALISS#INTERNATIONAL#CBSE c) OXALISS#INTERNATIONAL#THATCHUR d) None of these
  1. What is the purpose of the try block in Python error handling? a) To define the block of code where an exception may occur b) To catch and handle exceptions that occur within the block c) To ensure that the code executes without any errors d) To terminate the program if an exception occurs
  1. Which keyword is used to catch exceptions in Python? a) try b) catch c) except d) handle
  1. What is raised when a Python program encounters an error during execution? a) Error b) Exception c) Fault d) Bug
  1. Which of the following is NOT a standard Python exception? a) KeyError b) ValueException c) IndexError d) TypeError
  1. Which Python keyword is used to raise an exception manually? a) throw b) raise c) exception d) trigger
  1. What is the purpose of the assert statement in Python? a) To handle exceptions b) To terminate the program c) To check if a condition is true d) To raise an exception

Q20 and Q21 are Assertion(A) and Reason(R) based questions. Mark the correct choice as: (A) Both A and R are true and R is the correct explanation for A (B) Both A and R are true and R is not the correct explanation for A (C) A is

  1. Wah Bhyi Wah 2) WahBhyiaha 3) WahBhyiWah 4) WahBhyiWaha
  1. Predict the output of the following code: mylist = [2,14,54,22,17] tup = tuple(mylist) for i in tup: print(i%3, end=",")
  1. Write a Python program to reverse a string. 2 OR ( a) Given is a Python List declaration : list= [10, 20, 30, 40, 50, 60, 70, 80] print(list[ : : 2]) (b) Given a list L= [10, 20, 30, 40, 50, 60, 70], what would L[-3 : 99] return?
  1. Predict the output of following code: test_list = [5, 6, 7] test_tup = (9, 10) res = tuple(list(test_tup) + test_list) print(str(res))

OR

(a) Given is a Python string declaration: Word = "Connect Python” Write the output of: print(Word[: : 3]) (b) Write the output of the code given below: dict = {"Item": "Laptop", "Make": "LG" } dict["Price"] = 57000 dict["Make"] = "DELL" for k in dict: print(k, ‘@’, dict[k])

Q No. Section-C ( 3 x 3 = 9 Marks) Marks

  1. Predict the output of the following code: d = {"apple": 15, "banana": 7, "cherry": 9} str1 = "" for key in d: str1 = str1 + str(d[key]) + "@" + “\n” str2 = str1[:-1] print(str2) 3 OR Predict the output of the following code: line=[4,9,12,6,20] for I in line: for j in range(1,I%5): print(j,’#’,end=””) print() 3
  2. (^) Start with the list [11, 12, 13]. Do the following using list functions:
    1. Set the second entry (index 1) to 17
    2. Add 4, 5 and 6 to the end of the list
    3. Remove the first entry from the list
    4. Sort the list
    5. Double the list 6*½
  1. Insert 25 at index 3 OR A) What is the output of the following? print('KV Sangathan'.split('an')) (a) ['KV S', 'gath', ' '] (b) [‘KV Sangathan’,’an’] (c) [‘KV’,’Sang’,’athan’] (d) All of them B) Create the dictionary on data Exam=”PB” Year=”2013” Where exam and year are keys 1+
  2. 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") 3 Q No. SECTION D (4 X 4 = 16 Marks) Marks
  3. a) What possible output(s) are expected to be displayed on screen at the time of execution of the program from the following code? Also write the value assigned to variable first and second. from random import randint LST=[5,10,15,20,25,30,35,40,45,50,60,70] first = random.randint(3,8) – 1 second = random.randint(4,9) – 2 third = random.randint(6,11) – 3 print(LST[first],"#", LST[second],"#", LST[third],"#") i) 20#25#25# ii) 30#40#70# iii) 15#60#70# iv) 35#40#60# b) Rewrite the following code fragment using for loop: while num > 0 : count += 1 sum += num num –= 2 if count == 10 : print (sum/float(count)) break 2+ OR a) Find the output of the following: def main ( ) : Moves=[11, 22, 33, 44] Queen=Moves Moves[2]+= L=Len(Moves) 2+

finally: print("Finally block") B) What is the output of the following code? try: raise Exception("An error occurred") except Exception as e: print(e) finally: print("Finally block") Q No. SECTION E (2 X 5 = 10 Marks) Marks

  1. (a) Predict the output of the code given below: s ="Back2Basic" n = len(s) NS ="" for i in range(0, n): if (s[i] in “áeiou”): NS = NS + s[i].upper() elif (s[i] >= 'a' and s[i] <= 'z'): NS = NS +s[i].lower() else: NS = NS + '#' print(NS) b) Write the output on execution of the following Python code: S="Racecar Car Radar" L=S.split() for W in L: x=W. upper () if x==x[: : -1]: for I in x: print (I, end="*") else: for I in W: print (I, end="#") print() 2+
  2. Consider the following code and then answer the questions that follow : myDict = {'a' : 27, 'b' : 43, 'c' : 25, 'd' : 30} valA ='' for i in myDict : if i > valA : valA = i valB = myDict[i] print(valA) #Line print(valB) #Line print(30 in myDict) #Line myLst = list(myDict.items()) myLst.sort() #Line print(myLst[-1]) #Line
    1. What output does Line 1 produce?
    2. What output does Line 2 produce?
    3. What output does Line 3 produce?
    4. What output does Line 5 produce?
    5. What is the return value from the list sort( ) function (Line 4)? 5

************************ ALL THE BEST **************************