0% found this document useful (0 votes)
3 views6 pages

12 Iit Subjective-1 (40) Answer Key

This document is an examination paper for Class XII at Sagar International School, covering Computer Science with a total of 40 marks. It includes multiple sections with various types of questions, including true/false, coding problems, and theoretical questions related to programming concepts. The paper assesses students' understanding of Python programming, error handling, and data structures.

Uploaded by

Prasanna Sekaran
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)
3 views6 pages

12 Iit Subjective-1 (40) Answer Key

This document is an examination paper for Class XII at Sagar International School, covering Computer Science with a total of 40 marks. It includes multiple sections with various types of questions, including true/false, coding problems, and theoretical questions related to programming concepts. The paper assesses students' understanding of Python programming, error handling, and data structures.

Uploaded by

Prasanna Sekaran
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/ 6

SAGAR INTERNATIONAL SCHOOL, PERUNDURAI.

AFFILIATED NO: 1930419


SUBJECTIVE – I (APRIL’25)
CLASS:XII–IIT MARKS:40
DATE : SUBJECT:CS TIME :1½Hrs.
SECTION – A 18 * 1 = 18
1. False

2. GMAILbbCOM
3. KeyError
4. [1998, 2003, 2001, 2000]
[1998, 2002, 2002, 2000]
[1998, 2003, 2001, 2000]$
5. d. [23, 34, 65, 'Monitor', 32, 3]
6. b. yes
7. B. elif len(lst1) == len(lst2):
C. elif not(len(lst1) > len(lst2)) and not(len(lst1) < len(lst2))
E. elif not(len(lst1) is not len(lst2)):
8. ('abef', '', '')
9. c. z
10. c. values of a dictionary must be unique
11. AttributeError
12. a) Separate the exceptions using commas in except statement
13. c) To ensure that certain code will always be executed
14. b) Both A and R are True and R does not explain A
SECTION - B 7 * 2 =14
15. 1EAr5
16. def count_n_letter_words(file_name, n):
count = 0
with open(file_name, 'r') as f:
for line in f:
for word in line.split():
if len(word) == n:
count += 1
print("Number of", n, "letter words:", count)
17. def replace_kth_char(s, k):
result = ''
for i in range(len(s)):
if (i + 1) % k == 0:
result += '_'
else:
result += s[i]
print(result)
18. a) 10#25#15#
20#25#25#

d) 10#15#25#
15#20#10#

Minimum value of f, s, t = 1
Maximum value of f, s, t = 4
19. Actual Parameter Formal Parameter

Values passed to a function Variables defined in the function


during call header

In the function call In the function definition

Sends data to the function Receives data in the function

Can be constant, variable,


Always variables (placeholders)
expression

Exists in the calling function's Exists only within the function


scope body

Example:

def add(x, y): # x and y are formal parameters


print("Sum =", x + y)
a=5
b = 10
add(a, b) # a and b are actual parameters
Parameter Type Name Value Where it Appears

Formal Parameter x 5 In def add(x, y):

Formal Parameter y 10 In def add(x, y):

Actual Parameter a 5 In add(a, b) call

Actual Parameter b 10 In add(a, b) call

20.

Letter Scope Description


L Local Inside the current function
E Enclosing In enclosing (outer) function
G Global At the top level of the script or module
B Built-in Python’s built-in names like len, sum, etc.

x = "Global"

def outer():
x = "Enclosing"
def inner():
x = "Local"
print(x) # Will print "Local"
inner()

outer()
21. Find the errors and correct the code. Also, underline the
corrections made.
STRING= "WELCOME"
NOTE=" "
for S in range (0, len(STRING)) :
print (STRING [S])
SECTION – C 4 * 3 = 12
22. def words_without_vowels(file_name):
vowels = "aeiouAEIOU"
count = 0
file = open(file_name, 'r')
for line in file:
words = line.split()
for word in words:
has_vowel = False
for letter in word:
if letter in vowels:
has_vowel = True
break
if not has_vowel:
print(word)
count += 1
file.close()
return count

file_name = input(“enter the file name with extension:”)


count = words_without_vowels(file_name)
print("Number of words without vowels:", count)
23. def print_words_in_lexicographical_order(file_name):
with open(file_name, 'r') as file:
contents = file.read()
words = contents.split()
sorted_words = []
while words:
max_word = words[0]
for word in words:
if word > max_word:
max_word = word
while max_word in words:
words.remove(max_word)
sorted_words.append(max_word)
for word in sorted_words:
print(word)
file_name = "grammar.txt"
print_words_in_lexicographical_order(file_name)
24. def filter(oldfile, newfile):
try:
with open(oldfile, 'r') as infile:
with open(newfile, 'w') as outfile:
for line in infile:
if not line.startswith('@'):
outfile.write(line)
except FileNotFoundError:
print("File is not in the current location")

# Call the function


oldfile = "source.txt"
newfile = "target.txt"
filter(oldfile, newfile)
25. def push_book(BooksStack, new_book):
BooksStack.append(new_book)

def pop_book(BooksStack):
if len(BooksStack) == 0:
print("Underflow")
else:
return BooksStack.pop()

def peep(BooksStack):
if len(BooksStack) == 0:
print("None")
else:
print(BooksStack[-1])

# main block
BooksStack = []
push_book(BooksStack, ["The Great Gatsby", "F. Scott Fitzgerald",
1925])
push_book(BooksStack, ["1984", "George Orwell", 1949])
push_book(BooksStack, ["To Kill a Mockingbird", "Harper Lee",
1960])
peep(BooksStack)
print(pop_book(BooksStack))
peep(BooksStack)
print(pop_book(BooksStack))
print(pop_book(BooksStack))
# Trying to pop from an empty stack
pop_book(BooksStack)

You might also like