SET B Answerkey
SET B Answerkey
1. NEW – a newly created thread that has not yet started the execution
2. RUNNABLE – either running or ready for execution but it’s waiting for resource
allocation
4. WAITING – waiting for some other thread to perform a particular action without any time
limit
5. TIMED_WAITING – waiting for some other thread to perform a specific action for a
specified period
2. a.
output
{(4/7, 2/7)}
b.Create two 3*3 matrices and perform matrix multiplication and addition.
X = [[1,2,3],
[4 ,5,6],
[7 ,8,9]]
Y = [[9,8,7],
[6,5,4],
[3,2,1]]
result = [[0,0,0],
[0,0,0],
[0,0,0]]
for r in result:
print(r)
3. Code
def change_cases(s):
return str(s).upper(), str(s).lower()
chrars = {'a', 'b', 'E', 'f', 'a', 'i', 'o', 'U', 'a'}
print("Original Characters:\n",chrars)
result = map(change_cases, chrars)
print("\nAfter converting above characters in upper and lower cases\nand eliminating duplicate
letters:")
print(set(result))
Output:
4.
5.
6.
7. Output:
def average_tuple(nums):
result = tuple(map(lambda x: sum(x) / float(len(x)), zip(*nums)))
return result
nums = ((10, 10, 10), (30, 45, 56), (81, 80, 39), (1, 2, 3))
print ("Original Tuple: ")
print(nums)
print("\nAverage value of the numbers of the said tuple of tuples:\n",average_tuple(nums))
nums = ((1, 1, -5), (30, -15, 56), (81, -60, -39), (-10, 2, 3))
print ("\nOriginal Tuple: ")
print(nums)
print("\nAverage value of the numbers of the said tuple of tuples:\n",average_tuple(nums))
Output:
Part B
8. a(i).
Model: Handles data and business logic. Represents the business layer of the application
View: Presents the data to the user whenever asked for. Defines the presentation of the application
Controller: Entertains user requests and fetch necessary resources. Manages the flow of the
application
Model
public class Student {
private String rollNo;
private String name;
public String getRollNo() {
return rollNo;
}
public void setRollNo(String rollNo) {
this.rollNo = rollNo;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
View
Controller
Main program
8a ii
.
8 b ii. characteristics of functional programming
• Recursion - allows writing smaller algorithms and operating by looking only at the inputs to a
function
• Non-strict evaluation - allows having variables that have not yet been computed
Pattern matching - allows better type-checking and extracting elements from an object
9.a.i.
9.a.ii
1. Message Passing - the user makes calls to libraries to explicitly share information between
processors.
2. Data Parallel - data partitioning determines parallelism
4. Remote Memory Operation - set of processes in which a process can access the memory of
another process without its participation
9.b.i
class Time:
def __init__(self, hours=0, minutes=0):
self.hours = hours
self.minutes = minutes
def displayTime(self):
print(f"{self.hours}:{self.minutes}")
def displayMinutes(self):
print(f"{self.hours * 60 + self.minutes} minutes")
if __name__ == "__main__":
time1 = Time(2, 50)
time2 = Time(1, 20)
print("time1")
time1.displayTime()
print("time2")
time2.displayTime()
9.b.ii
Concurrent programming is programming with multiple tasks. The major issues of concurrent
programming are:
Objects shared by multiple tasks have to be safe for concurrent access. Such objects are called
protected. Tasks accessing such an object interact with each other indirectly through the object.
• Lock-free, when the task accessing the object is not blocked for a considerable time;
• Blocking, otherwise.
Blocking objects can be used for task synchronization. To the examples of such objects belong:
• Events;
• Mutexes and semaphores;
• Waitable timers;
• Queues
import socket
def server_program():
# get the hostname
host = socket.gethostname()
port = 5000 # initiate port no above 1024
if __name__ == '__main__':
server_program()
Client Program:
import socket
def client_program():
host = socket.gethostname() # as both code is running on same pc
port = 5000 # socket server port number
client_socket = socket.socket() # instantiate
client_socket.connect((host, port)) # connect to the server
if __name__ == '__main__':
client_program()
a.ii.
10. b. i.
from automata.fa.dfa import DFA
# DFA which matches all and in ‘bb’
dfa = DFA(
states={'q0', 'q1', 'q2'},
input_symbols={'a', 'b'},
transitions={
'q0': {'a': 'q0', 'b': 'q1'},
'q1': {'a': 'q0', 'b': 'q2'},
'q2': {'a': 'q0', 'b': 'q2'}
},
initial_state='q0',
final_states={'q1'}
)
dfa.read_input('abb') # answer is 'q1‘
dfa.read_input('ab') # answer is error
print(dfa.read_input_stepwise('ab'))
if dfa.accepts_input('abb'):
print('accepted')
else:
print('rejected')