0% found this document useful (0 votes)
127 views14 pages

CBSE Practice Questions

Uploaded by

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

CBSE Practice Questions

Uploaded by

Varada
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 14
Practice Questions - Class: XII Session: 2021-22 Computer Science (Code 083) (Theory: Term-1) 1. If the value of j is 5, the expression i! has the value False has the value True sets the value of i to 6 sets the value of i to -5 oe 2. The main difference between the modes 'w’ and ‘a! when opening a file in Python is that a. 'w is used for writing a file and 'a' for reading a file. b. 'w over-writes an existing file while 'a' writes to the end of the file, c. 'w is used with text files while 'a' is used with binary files d._'w gives an error if the file does not exist while 'a' creates it with no error. 3. Sushma gets the current date and time as a string x. Its value is "2021-10-30 12:49:48..216062", Sushma prints the value of x[11:16] and gets "12:49". Which of these will contain the date in yyyy- mm-dd format? x[8:9] x(0:10] x[1:10] x{tt3] 4, Python's Pickle module is used for serializing and de-serializing any Python object structure and dumping / loading it to or from a binary file. Which of these is a case where it can be useful? graphically representing the contents of any Python object on the screen sorting a large list of numbers in ascending or descending order quickly storing the data in any Python object for later reconstruction or use compressing a large dataset so that it can be saved in less than a tenth of the space Which of these Python data structures cannot have duplicate items and does not support ordering? a. list b. tuple ©. dictionary d. set . Which of these Python data structures would be most suited to store the list of Indian states and their corresponding capitals? list tuple dictionary set pegs The statement p -= 5 has the same effect as which of these statements? p-s =5-P . Which output lines of the following program will print the same results? tupl = (10, 2, 30, 40, 50, 6, 70, 80, 9@) print(tup1[S:-1]) print(tup2[51) print(tup1[5:]) print(tup1[-4:8]) a, (1) and (2) b. (land (4) ©. @)and 3) d. (1), G) and (4) Every time Raj's python program accesses the internet, it records the time and website accessed in a log file ‘internet_access.log’. This is one of the sample lines in the log file: 2021-09-01 10:03:00, www.google.com Which of these lines would be used by the program to open the file? logfile = open("internet_access.log', ‘rb*) logfile = open(' internet_access. log" ,'w') logfile = open('internet_access.log’, ‘at") logfile = open(’internet_access.log', ‘ab’) 10. 12. 15, Which of these fimetions can be used to set a file's current position? seek() set() tell) open() eee When setting the current position of a file, the position CANNOT be set with reference to which of these? the beginning of the file the current file position the middle of the file the end of the file eaege Ifa function is defined by the line "def calculate(p, q=100, r=10) true? which of the following is a. p isan optional parameter ». qand r are optional parameters c. q will always have value 100 in the function 4. the above line will cause a syntax error Which of these points about the return statement is FALSE? ‘A return statement can only be used inside a funetion A retum statement can be used without any expression When encountered, a return statement terminates a function ‘A function cannot have more than one return statements oe ACSV file isa text file can store images is a type of python program isa Computer Software Validation file eege Python's abs() function retums the absolute value of number passed to it. For example abs(5) is equal to 5 and abs(-3.1) = 3.1. What will be the value of abs(3 - abs(-10)) 13, “13, ergs 16. Which of these statements about text and binary files is true? A text file has the same number of characters in each line unlike a binary file. A text file has a special End Of File character unlike a binary file An HTML file is an example of a text file while a CSV file is an example of a binary file. Every character in a text file can occur in a binary file but the reverse is not true. eaoge Read the below and answer questions 17 and 18: The exponentiation operator in Python (**) has higher precedence than the division (/) and multiplication (*) operators, meaning that ** will be evaluated before / and * in an expression. Operators / and * have the same precedence. Further, ** evaluates from right to left, meaning that if an expression has multiple operators of the same precedence of **, the operator on the right will be evaluated before the operator on the left. On the other hand, / and * evaluate from left to right. 17, Which operator will be evaluated first in this expression? 6tae2e2/2 . the first ** from the left the second ** from the left / 18. What will be the value of this expression: asrz3ar2 a. 16.0 b. 10 cd d. 1/16 19. Which of these statements about for and while loops in Python is TRUE? a. A for loop usually run a given number of times; a while loop runs while a condition is met. b. Statements in a for loop are always run at least once; those in a while loop may never be run. c. A for loop cannot contain another for loop; a white loop can contain another while loop. 4. A for loop always has to have a loop counter; a while loop never uses a loop counter. 20, How does a Python program know where a FoR block ENDS? a, when it finds a closing bracket (}) character b. when it finds the keyword ENDFOR ¢. when it finds a line with matching indentation 4. when it finds a colon (:) character 21. Sonal wrote the following program print_students. py to print the number of students in her class. class = 5 section students = 30 print ("There are", students, “students in class", class, section) However, when she ran the program, she got the following output: File ".\prin class = 5 Syntaxerror: invalid syntax students.py", line 1 Which of these changes will make the program run without error? a. writing '=-' instead of '' (correct assignment operator) b. writing "5" instead of 5 (variable should be a string) changing the variable name (‘class' is a reserved word) 4. adding a colon (':') at the end of the statement (begin indented block) Read the following and answer questions 22 and 23: A log file records the time, userid, record number and number of bytes read from a certain database. Each of the fields uses a fixed number of bytes. The last 3 lines of the file were as follows at some time: 22, What is the inter-field delimiter used by the file? a, Comma (,) b. Colon () ©. Double-colon(::) 4. Hyphen (-) 23. Which of these lines will return the latest entry from the file? (Assume the file handler is file and SEEK_START and SEEK_END represent the offsets from the beginning and end of the file respectively) file.seek(-45, SEEK_END) fille.seek(45, SEEK_END) fille.seek(135, SEEK START) file.seek(-135, SEEK START) 24, The advantage of opening a file using the with clause instead of the open() function is that the access mode does not have to be specified the file does not have to explicitly be closed the filename does not have to be specified the file gets opened for reading and writing eacge 25. What should appear in the place of the "?" symbol in the table below? mystring = "I love Python" Expression Value aystring[-1] 7 mystring[-3:] hon mystring[5?=4] z e. e Py f. ve B. evol he ython 26, Identify the error in the program below: Anport pickle print("The data that were stored in file are: ") Fileobject-open("*nydata.dat*,"r") objectvar-pickle. load(fileobject) Fileobject .close() print(objectvar) ‘The 3rd line should be Fileobject=open("nydata. dat", "rb") The 4th line should be objectvar=pickle. dump (Fileobject) The Fileobject.close() statement should come AFTER the print(objectvar) statement The last line should be print(fileobject) 27. What will be the output of this program? P = None qe : if (p == a) print ("None is the same as @") elif (p ry: print ("None is the same as empty string") elif (p ) print ("None is the same as the string ‘None else: print ("None of the above") None is the same as 0 None is the same as empty string None is the same as the string ‘None’ None of the above In Python, lists are mutable and tuples immutable. See the program and answer questions 28 and 29: List_items Dravid", ‘tuple_itens = ("Sunday", "Monday’ List_items[4] = "Harbhajan" tuple_itens[4] = “Friday print(List_items(4], tuple_items[4]) "Tuesday", “Wednesday” Thursday") 28, In python, the term mutable means: memory-efficient fixed changeable sequential aoge 29, What will be the output of this program? Sourav Thursday Harbhajan Friday An error will be reported on line 3 An error will be reported on line 4 30, What will be the output of this program? (All quotes shown are double quotes) message = “My favourite movie is "3 Idiots"" print (message[23: ]) a. 3 Idiots b. 3 Idiots"" d «Syntax error on line 1 |. Syntax error on line 2 31. What will be the output of this program? question = “How are you, Ravi?" x = txt. find(",") y = txt. find("?") print (txt[x+2:y]) a. How are you Ravi b. How are you c. Ravi d. Ravi? 32. What will be the output of this program? mea ne"D print (str(m) +n) al b. 2 eo d. Syntax Error 33, 34, ‘What will be the output of this Python lin. print("This is Delhi. # Delhi is the capital of India.") # This is a comment. This is Delhi. This is Delhi. # Delhi is the capital of India. # This is a comment. This is Delhi. # Delhi is the capital of India. This is Delhi. This is a conment. What will be the output of this program? a2" print(p+q, r+s) 17 18 125 108 17 108 125 18, Study the following program which has an unintended error and answer questions 35 and 36. [Recall that range (m, n) is all integers from m to n-1] 36, tea while (i <= 1@) # For every nunber i from 1 to 10 sun = @ Set sum to @ for x in range(1,4#1): sum += x # Add every nunber fron 1 to i print(i, sum) # print the result What is the programmer trying to do in the program? Print all the odd numbers from 1 to 10 Print the total of all numbers from 1 to 10 For each number till 10, print the sum of numbers between 1 and the number. For each number till 10, print the sum of the number and its previous number Identify the error in the program sum = 0 should be BEFORE the while statement The range should be from 0 (not 1) to i+ 1 i=i +1 should be added after the print statement There is no error in the program aoge 37. What will this program output? (Recall that 5% 3 =2, 10% 2=0 and 7 %3~= 1] for i in range(@, 100): if (1 %3 == @) or (1% 4 == 8): ‘continue print (i) All numbers less than 100 that are multiples of 12 All numbers less than 100 that are NOT multiples of 12 All numbers less than 100 that are multiples of 3 or 4 All numbers less than 100 that are NOT multiples of 3 or 4 38. See the following program snippet which lists out the names of all students: student_list = ["Ravi", "Sunita", “Gopal”, "Salma", “Lily"] number_of_students = len(student. list) ise while 4 <= number_of_students: print(student_list[i]) deed ‘When it was run, it gave the following error on the last line IndexError: list index out of range Which of these will correct the error? Replacing i = @withi = 1 Replacing i <= nunber_of_students with i < nunber_of_students Replacing student_1ist[i] with student_list[i-1] Replacing i += 1withi = i+ 1 oe 39, See the code below using Python's pickle module to STORE data into file ‘Latlong data’: import pickle data = ['New Delhi’, '28.6139° N', '77.2090° E'] File = open(*Latlong data’, __(2)__) pickle.__(2)___(data, file) file.close() What, respectively, should appear in blanks (1) and (2)? a. ‘rb! and dump b, ‘wo! and dump c. ‘rb! and load d. ‘wo! and load 40. What will be the value of p and r at the end of this program’ p= 40 r= 50 peper rep-r p=p-r print (p, r) a. p= 40, r= 40 b. p= 58, r= 50 c. p= 58, r= 40 d. p= 40, r= 50 Read the following and answer questions 41 and 42. File ‘RoadNotTaken.txt' has these lines: Two roads diverged in a wood, and I~ I took the one less traveled by, ‘And that has made all the difference. The following code opens this file: fp = open("RoadNotTaken.txt", ‘r') poem = fp.readlines() print (Len(poen)) #p.close() 41, What is the data type of the variable poem? string list tuple dictionary 42, What will be the output of the above program? a2 b. 3 8 d. 22 43. The score of a student in a test is stored as a Python tuple. The test had 3 questions, with some questions having subparts whose scores are recorded separately, score = (6, (5, (2, 1), 8), (4 3, (1, 3, 2))) print (score(2}{2]) ‘What will be the output of this program snippet? a. (1, 3, 2) b. (2, a) 3 a8 44, What will be the output of the program snippet below: India"): "United States": "41") def phone_with_country_code (phone_number, country country_codes = {"India": "491", "Singapore": "465", if country not in country_codes: return("Country is not supported") return (country_codes[country] +" " + phone_sunber) 19876500001"), " print(phone_with_country_code! phone_with_country_code("203-687- 1232", "United States")) India 9876500001 | United states 203-607-1232 +91 9876500001 | +1 203-607-1232 9876500001 | +1 203-607-1232 9876500001 | United States 203-607-1232 45, The choice() method of Python's random module returns a random element from a list. See the program below, import random suits cards “Hearts”, "Clubs", "Diamonds", "spades") face", "2", "3", "a", "5", "6", *7", » "Jack", "Queen", "king") card_picked = random.choice(cards) +" of " + random.choice(suits) print (card_picked) Which of these COULD be an output of this program? a. Hearts Ace b. Diamonds of Queen c. TofKing d._ Jack of Clubs 46, Study the manual entry for the split() method given below. split (sep=None, maxsplit=- 1) Return a list of the words in the string, using sep as the delimiter string. If maxsplit is given, at most maxsplit splits are done (thus, the list will have at most maxsplit + elements). If maxsplit is not specified or -1, all possible splits are made. What will be the output of the program given below? 1821-88-09 10:22:03: : 0483: 106384626: :00001024" string = parts = string split("::", 2) print (parts) a. ['2021-e8-09 10:22:83", ‘e4a: b. ['2021-@8-09 10", '22', '@3::0443: :@6384626: 00001024" ] c. ['2021-@8-09 10:22:63", '8443", "96384626: :00001024' ) d. ['2021-8-@9 10:22:03", '@443', '@6384626', '90001024"] 26384626: :00001024' ] 47. What will be the output of this program? ea def change_values(): global » a-5 P=peg return (p) change_values() print(p, q) Read the information below and answer questions 48 and 49 In Python and other languages, a ‘regular expression’ is a pattern of characters in which some characters have a special meaning. Specifically 1. Any characters enclosed within square brackets ([]) represent any one of those characters 2.A* following a character represents zero or more of those characters. 3. All letters and digits represent themselves Thus: ‘ab* could represent ‘a, ‘ab, 'abb’,'abbb' and so on but NOT ‘bbb’ or ‘aba’, (Rules 2 and 3) star[ekt} could represent ‘stare, ‘stark’ or ‘start’ but NOT 'star' or ‘are’ (Rules 2 and 3) albed* could represent ‘a, ‘ab’, ‘abc, ‘acdd! and so on but not ‘aba’ or ‘aa’ (Rules 1-3) 48, Which of these would NOT be represented by [ab]e*? abe be bece 49. A factory codes its products using a series of letters and numbers. Each code starts with 10, 11 or 12 (representing different production locations), followed by an S, M or L (for Small, Medium or Large), followed by a 4 digit number. Which of the following would represent this? a. [101222] [SML]1234 b. 1[o12]}smL [123456789] ¢. 1[e12][SML][0123456789] [0123456789] [0123456789] [0123456789] d. [012] [012] [SML] [6123456789] [0123456789] [0123456789] [0123456789] Nagesh and Simran have written this Python program. It asks for a student's name and roll no. If both match the records in a CSV file, it displays the student's English, Maths and Computer Science marks. ‘The marks data is stored in a file student_marks.csv whose first 3 rows are as shown below: Nane,Roll No, Comments English, Maths Computer Science Nagesh Rao, 12342, ,85,92,96 ‘Simpan Shah,14324,Absent for English test,A,87,99 Ravi Gulati, 43234, ,76,97,81 Study the program and answer the questions that follow: import csv print("Enter your name and roll nunber to see your subject marks. name = input("Enter Nane exactly as in Hall Ticket: ") rollno = input("Enter Roll No.: ") with open(‘student_marks.csv" 1 ) as csv_file: csv_reader = csv.reader(csv_file, deliniter=",') Line_count = @ match_found = False for row in csv_reader: Line_count += 1 if Line_count —@) else: if row[0]-lower() match_found = True eng_marks = row[3] maths_narks = row[4] cs_marks = row[S] print("\n"+row[@]+ roLIno name.lower() and row[1] marks are:\nEnglish:",eng_marks) s\n") print(*Maths:", maths_marks, “\nComp Sc:", ¢s_marks,"\n\nThank you!) —_G) if match_found == Fals print ("\nNo matching name and roll number found. Please check and re-enter”) 50, What mode of opening should come in blank 1? aw boa c. wb d. 51. What statements, respectively, should come in blanks 2 and 3? Choose the BEST answer. a. continue and continue b. break and break ©. break and continue d. continue and break 52, What is the data type of the variable match_found? bytes str int bool 53. The file student_marks.csv contains a comment field in every row. Which of these comments may cause the program to fail to read that row properly? New student who joined school in Dec School Topper in English! Absent for English, Maths papers ergs 54, Which of these is an error in the program? a. line_count should be initialised to 1 (not 0) in line 9. b, The last 2 lines should have one less indentation. c. The file opened for reading is not closed using close() d. None of the above. 55, For the names shown in the sample data, assuming the roll number is entered correctly, which of these will NOT find a match? Nagesh Rao Simram Ravi Gulati ‘Simran shah

You might also like