ABOUT THE COURSE :
Summary | |
---|---|
Course Type | Elective |
Duration | 12 weeks |
Category | Computer Science and Engineering |
Start Date | 22 Jan 2024 |
End Date | 12 Apr 2024 |
Exam Registration Ends | 16 Feb 2024 |
Exam Date | 21 Apr 2024 IST |
Assignment Solutions :
Programming Assignment :
1. Programming Assignment | Week 10
def rotate(mat):
"""
Rotate a matrix 90 degrees clockwise
Argument:
mat: list of lists
Return:
rotated_mat: list of lists
"""
if not mat:
return list()
rows = len(mat)
cols = len(mat[0])
rotated = [[0] * rows for csk in range(cols)]
for ipl in range(rows):
for jk in range(cols):
rotated[jk][rows - 1 - ipl] = mat[ipl][jk]
return(rotated)
2. Programming Assignment | Week 10
def is_magic(matrix):
"""
determine if a matrix is magic square
Argument:
mat: list of lists
Return:
string: 'YES' or 'NO'
"""
n = len(matrix)
magic_sum = sum(matrix[0])
for r1 in matrix:
if sum(r1) != magic_sum:
return "NO"
for j in range(n):
column_sum = sum(matrix[i][j] for i in range(n))
if column_sum != magic_sum:
return "NO"
diagonal_sum1 = sum(matrix[i][i] for i in range(n))
diagonal_sum2 = sum(matrix[i][n - 1 - i] for i in range(n))
if diagonal_sum1 != magic_sum or diagonal_sum2 != magic_sum:
return "NO"
return("YES")
3. Programming Assignment | Week 10
You are given certain details of the trains that stop at a
station. Your task is to store these details in a nested dictionary.
The first line of input is n, the number of
trains that stop at the station. n blocks of input follow. The
first line in each block corresponds to the train name. The second line in each
block corresponds to m, the number of compartments in the
train. m lines of input follow. Each of these m lines
has two values separated by a comma: name of the compartment and number of
passengers in it.
Your task is to create a nested dictionary named station_dict.
The keys of the dictionary are train names, the value corresponding to a key is
another dictionary. The keys of the inner dictionary are the compartment names
in this train, the values are the number of passengers in each compartment. For
example:
{
'Mumbai Express': {
'S1': 10,
'S2': 20,
'S3': 30
},
'Chennai Express': {
'S1': 10,
'S2': 20,
'S3': 30
}
}
(1) The values of the compartments should be represented as integers and not as strings.
(2) You do not have to print the output to the console. Do not try to print the output that you observe in the "Expected Output". You just have to process the input and create the dictionary station_dict.
n = int(input())
station_dict =dict()
for chapri in range(n):
train_name = input()
m = int(input())
compartments = {}
for hardik in range(m):
compartment, passengers = input().split(",")
compartments[compartment] = int(passengers)
station_dict[train_name] = compartments
CRITERIA TO GET A CERTIFICATE :
- Average assignment score = 25% of average of best 8 assignments out of the total 12 assignments given in the course.
- Exam score = 75% of the proctored certification exam score out of 100
- Final score = Average assignment score + Exam score
Follow Us