Professional Documents
Culture Documents
MID Term Assessment Testqs and Ans
MID Term Assessment Testqs and Ans
MID Term Assessment Testqs and Ans
CodeTest 1a
i-th term in the Product sequence, denoted by Ai is defined as the Product of the numbers from 1 to i.
The Product sequence is recursively defined as : Ai=A(i-1)*i, i >1, A1=1. For example, A5=1 * 2 * 3 * 4
* 5 = 120
1, 2, 6, 24, 120
Given a value ‘n’, build a dictionary with first ‘n’ terms of the Product sequence as keys and the list of
their odd divisors as their values. For example, if ‘n’ is 5, then the expected output is:
{1: [1], 2: [1], 6: [1, 3], 24: [1, 3], 120: [1, 3, 5, 15]}
Print the dictionary in ascending order of key. Use pprint function for printing dictionary in sorted order.
pprint(dictionary name)
Include the line “from pprint import pprint” in the top of your program
Input Format
Output Format
A dictionary with terms of the product sequence as key and their odd divisors as values. Print the
dictionary in ascending order of key
Codetest-1b
Index sum sequence is generated by summing the indices of the position. i-th term in the Index sum
sequence, denoted by Ai is defined as Ai= sum of the numbers from 1 to i. Index sum sequence is
recursively defined as : Ai=A(i-1)+i, i >1, A1=1. For example, A5=
1 + 2 + 3 + 4 + 5 = 15.
Index sum sequence upto eight terms would be:
Given a value ‘n’, build a dictionary with first ‘n’ terms in the sequence as keys and the list of their
divisors as their values. For example, if ‘n’ is 8, then the expected output is:
Print the dictionary in ascending order of key. Use pprint function for printing dictionary in sorted order.
pprint(dictionary name)
Include the line “from pprint import pprint” in the top of your program
Input Format
Output Format
A dictionary with the terms of ‘index sum sequence’ as key and their divisors as values. Print the
dictionary in ascending order of key
Codetest – 2a
Given three positive integers, write an algorithm and the subsequent Python code to check whether the
given three integers can represent the length of the three sides of a triangle. In any triangle, sum of the
lengths of any two sides must be greater than the length of the third side. For example, since 3 < 4+5, 4 <
3+5 and 5<3+4, the triplet (3, 4, 5) can represent the lengths of the of sides of a triangle. Since the sum
5+4 is not greater 11 the triplet (5,4,11) cannot represent the length of sides of a triangle.
Input Format:
First integer
Second integer
Third integer
Output Format:
Print Yes if they can represent the length of sides of a triangle and No otherwise
Codetest 2b
BCCI maintains a table of team member’s run score in three one day matches. Players are identified by
their Player_ID. Team managers check the member’s performance based on their run scores in 3matches
in a year. Given the details of the players in the team, their score in three matches and a player ID ‘p’,
write an algorithm and the subsequent Python code to determine the total score and the position of player
‘p’. Player ‘p’ is in position 1 if he has got the maximum score. Assume that all players have different
total score. For example, if the given Player_ID is A1 then the expected output is
A1
132
Player_I Score
D s
12
A1 25
95
22
A2 55
60
20
A3 25
0
78
A4 65
0
54
A5 76
0 Input Format
Total No.of. Players
Player_id1,Score_1,Score_2,Score_3
Player_id2,Score_1,Score_2,Score_3
Player_idn,Score_1,Score_2,Score_3
Output Format
Player_ID
Player Position
Debugging
#. There are ‘n’ numbers of students in a class. They have secured some percentage mark in their CAT- I
Examination for the subject CSE1001. Find the maximum and minimum mark among the students.
'''
Input format:
Output format:
marks=()
n=int(input())
for i in range(0,n):
s = int(input())
marks = marks+(s,)
min=max=marks[0]
#Start Deb
for i in range(1,n):
if(min>marks[i]):
min=marks[i]
if(max<marks[i]):
max=marks[i]
#End Deb
print(min)
print(max)
#2. Design a search engine for train dataset like “Googletrain” which is used to search whether the
particular train is running for the day or not. The train dataset contains “Train Number” as a field . Write
a python program to get train number as the input and to locate whether that particular train number is
available in the dataset or not. If the train is running on the particular day then display ”1”, else display
“0”.
'''
Input format:
Read s # Train_No
Output format:
'''
Train_No=()
n=int(input())
for i in range(0,n):
s = int(input())
Train_No = Train_No+(s,)
X=int(input())
i=0
count=0
#Start Deb
while (i<len(Train_No)):
if(X==Train_No[i]):
print(1)
count=count+1
break
else:
i=i+1
else:
print(0)
#End Deb
#3. Validate the Password using regular expression.
'''
Sample Input:
Anusooya123#
Sample Output:
Invalid
Sample Input:
Anu123#
Sample Output
Valid
'''
import re
passwd = input()
#Start Deb
reg = "^(?=.*[A-Z][a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*#?&])[A-Za-z\d@$!#%*?&]{6,10}$"
#End Deb
pat = re.compile(reg)
mat = re.search(pat, passwd)
if mat:
print("Valid")
else:
print("Invalid")
#4
key_value ={}
key_value[2] = 56
key_value[1] = 2
key_value[5] = 12
key_value[4] = 24
key_value[6] = 18
key_value[3] = 323
#SD
#ED
#5
x=5
x >>= 3
#
print(x)
#output0
#6
#SD
#ED
for x in adj:
for y in fruits:
print(x, y)
'''
red apple
red banana
red cherry
big apple
big banana
big cherry
tasty apple
tasty banana
#7
#SD
for x in range(6):
print(x)
#ED
else:
print("Finally finished!")
'''
for x in range(6):
print(x)
else:
print("Finally finished!")
Finally finished!
'''
#8
i=1
while i < 6:
print(i)
if (i == 3):
break
#SD
i += 1
#ED
'''
'''
#9
import re
#SD
x = re.findall("falls|stays", txt)
print(x)
#ED
if x:
print("Match")
else:
print("No match")
#10
import re
#SD
x = re.findall("\D", txt)
#ED
if x:
print("Match")
else:
print("No match")
MCQ
1. import re
x = re.findall("[^a-s]^\S", txt)
if x:
print("Match")
else:
print("No match")
Output
1. Match
2. No Match
3. Error
4. None
2.
import re
x = re.findall("Spain\Z", txt)
if x:
print("Match")
else:
print("No match")
Output
1. Match
2. No Match
3. Error
4. None
3.
print(mydoubler(11,2),mytripler(11,3))
Output
22 33
1111 111111
23
Error
4.
key_value ={}
key_value[2] = 56
key_value[1] = 2
key_value[5] = 12
key_value[4] = 24
key_value[6] = 18
key_value[3] = 323
output
[(1, 2), (5, 12), (6, 18), (4, 24), (2, 56), (3, 323)]
{(1, 2), (5, 12), (6, 18), (4, 24), (2, 56), (3, 323)}
[(1, 2), (2, 56), (3, 323) ,(4, 24), (5, 12), (6, 18)]
{(1, 2), (2, 56), (3, 323) ,(4, 24), (5, 12), (6, 18)}
5.
x=2
y=5
print(x ** y)
output
1. 32
2. 10
3. 25
4. 20
1
6.
x = ["apple", "banana"]
output
1. True
2. False
True
7.
x = ["apple", "banana"]
y = ["apple", "banana"]
z=x
print(x is not z)
output
1. True
2. False
False
8.
print(type(list1))
output
abc,34,True,40,male
<class 'list'>
['abc', 34, True, 40, 'male']
3
9.
Output
for x in list2:
list1.append(x)
list1.extend(list2)
10.
thistuple = ("apple")
print(type(thistuple))
output:
<class 'tuple'>
<class 'str'>
<class ‘thistuple’>
<class,class>
11.
print(green)
print(yellow)
print(red)
output:
1. apple
banana
['cherry', 'strawberry', 'raspberry']
2. apple
banana
cherry
strawberry
raspberry
3. apple
banana
cherry
4. apple
banana
cherry strawberry raspberry
1
12.
numb = (1,2,3)
mytuple = numb * 2
print(mytuple)
output
(1, 2, 3, 1, 2, 3)
2, 4, 6
11, 22, 33
(1, 1, 2, 2, 3, 3)
13.
print(thisset)
output:
14.
set2 = {1, 5, 7, 9, 3}
print(set1+set2+set3)
print(set2)
print(set3)
Output
1. Error
2. {'apple', 'cherry', 'banana'}
{1, 3, 5, 7, 9}
{False, True}
3. { {'apple', 'cherry', 'banana'},{1, 3, 5, 7, 9},{False, True}}
{1, 3, 5, 7, 9}
{False, True}
4. {'apple', 'cherry', 'banana', 1, 3, 5, 7, 9,False, True}
{1, 3, 5, 7, 9}
{False, True}
1
15.
thisset.remove("bananan")
print(thisset)
output
Error
16.
del thisset
print(thisset)
output:
Error
17.
z = x.intersection(y)
x.intersection_update(y)
print(z)
print(x)
Output
1. {'apple'}
{'apple'}
2. {'apple'}
{'google', 'microsoft', 'apple'}
3. {'google', 'microsoft', 'apple'}
{'apple'}
4. {'google', 'microsoft'}
{'banana', 'cherry'}
1
18.
z1 = x1.issuperset(y1)
z2 = x2.issuperset(y2)
print(z1)
print(z2)
Output
1. True
False
2. False
True
3. True
True
4. False
False
19.
thisdict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
thisdict.pop()
print(thisdict)
output
1. Error
2. {'brand': 'Ford', 'year': 1964}
3. {'brand': 'Ford', 'model': ‘Mustang’}
4. {''model': ‘Mustang’, ‘year': 1964}
20.
Output
To print empty
To print nothing