12 Iit Subjective-1 (40) Answer Key
12 Iit Subjective-1 (40) Answer Key
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
Example:
20.
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
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)