The Joy of Computing Using Python Week 7 Solutions

The Joy of Computing using Python | NPTEL 2023 | Week 7 Assignment Solutions

ABOUT THE COURSE :
Week 7

A fun filled whirlwind tour of 30 hrs, covering everything you need to know to fall in love with the most sought after skill of the 21st century. The course brings programming to your desk with anecdotes, analogies and illustrious examples. Turning abstractions to insights and engineering to art, the course focuses primarily to inspire the learner's mind to think logically and arrive at a solution programmatically. As part of the course, you will be learning how to practice and culture the art of programming with Python as a language. At the end of the course, we introduce some of the current advances in computing to motivate the enthusiastic learner to pursue further directions.

Course Status     :    Upcoming
Course Type        :    Elective
Duration               :    12 weeks
Start Date            :    23 Jan 2023
End Date              :    14 Apr 2023
Exam Date           :    29 Apr 2023 IST
Enrollment Ends :    30 Jan 2023

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

YOU WILL BE ELIGIBLE FOR A CERTIFICATE ONLY IF AVERAGE ASSIGNMENT SCORE >=10/25 AND EXAM SCORE >= 30/75. If one of the 2 criteria is not met, you will not get the certificate even if the Final score >= 40/100.

NOTE: Please note that there will not be an unproctored programming exam for this course this term.

The Joy of Computing using Python Week 7 Assignment Solutions :-

Q1) Which of the following is/are uses of functions?
a) Gives a higher-level overview of the task to be performed
b) Reusability- uses the same functionality at various places
c) A better understanding of code
d) All of the above
e) None of the above

Answer :- (d) All of the above 

Q2) What is the output of the following spiral print python function?
WEek 7

a) 1 2 3 4 5 6 12 18 17 16 15 14 13 7 8 9 10 11
b) 1 2 3 4 5 6 12 18 17 16 15 14 13
c) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
d) 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1

Answer :- (b) 1 2 3 4 5 6 12 18 17 16 15 14 13 

Q3)Which of the following library moves the turtle backward?
a) turtle.back(distance)
b) turtle.bk(distance)
c) turtle.backward(distance)
d) All of the above

Answer :- (d) All of the above 

Q4) Which of the following library has to be imported to plot the route map using GPS locations in python?
a) gmplot
b) csv
c) both
d) None

Answer :- (c) both 

Q5)bytes, bytearray, memoryview are type of the _ data type.
a) Mapping Type
b) Boolean Type
c) Binary Types
d) All of the above
e) None of the above

Answer :- (c) Binary Types 

Q6) In the Snakes and Ladders game, the least number of times a player has to roll a die with the following ladder positions is _____ ladders = { 3: 20, 6: 14, 11: 28, 15: 34, 17: 74, 22: 37, 38: 59, 49: 67, 57: 76, 61: 78, 73: 86, 81: 98, 88: 91 }
a) 4
b) 5
c) 6
d) 7

Answer :- (b) 5 

Q7) Which of the following code snippet will create a tuple in python?
a) name = (’kiran’,’bhushan’,’madan’)
b) name = {’kiran’,’bhushan’,’madan’}
c) name = [’kiran’,’bhushan’,’madan’]
d) None of the above

Answer :- (a) name = (’kiran’,’bhushan’,’madan’) 

Q8) What does the following program plot?
week 7
a) Plots the random number generated in each iteration
b) Plots the number of times the given input matches with the random number generated
c) Plots the input entered for each iteration
d) none of the above

Answer :- (b) Plots the number of times the given input matches with the random number generated 

Q9) Sentiment analysis involves working with _____
a) a piece of information is useful or not
b) a piece of information is biased or unbiased
c) a piece of information is true or false
d) a piece of information is positive or negative

Answer :- (d) a piece of information is positive or negative 

Q10) What does the following code snippet in python compute
week 7

a) checks whether the two given texts are the same
b) searches for text2 in text1
c) finds all the occurrences of text2 in text1
d) none of the above

Answer :- (c) finds all the occurrences of text2 in text1 

 Week 7 Programming Assignment 1 :- 

DiagCalc that calculates the sum of left and right diagonals and prints it respectively.

Input:

A Number M 
A Matrix with M rows and M columns
[[1,2,3],[3,4,5],[6,7,8]] 

Output 
13
13
Week 7 Programming Assignment 1
def DiagCalc(m):
    l=0
    r=0
    j=len(m)-1
    for i in range(len(m)):
        l=l+m[i][i]
        r=r+m[i][j]
        j=j-1
    print(l)
    print(r,end="")
     
        
n = int(input())
M = []
for i in range(n):
    L = list(map(int, input().split()))
    M.append(L)
DiagCalc(M)                                                                                                                                                                                                                                                

 Week 7 Programming Assignment 2 :- 

Given a matrix M write a function Transpose which accepts a matrix M and return the transpose of M.
Transpose of a matrix is a matrix in which each row is changed to a column or vice versa.

Input 
A matrix M
[[1,2,3],[4,5,6],[7,8,9]]

Output
Transpose of M
[[1,4,7],[2,5,8],[3,6,9]]
Week 7 Programming Assignment 2
def Transpose(N):
    M=[]
    for i in range(len(N)):
        k=[]
        for j in range(len(N[i])):
            k.append(N[j][i])
        M.append(k)
    return M

 Week 7 Programming Assignment 3 :- 

Given a matrix M write a function snake that accepts a matrix M and returns a list which contain elements in snake pattern of matrix M. (See explanation to know what is a snake pattern)

Input
A matrix M
91 59 21 63 
81 39 56 8 
28 43 61 58 
51 82 45 57

Output
[91, 59, 21, 63, 8, 56, 39, 81, 28, 43, 61, 58, 51, 82, 45, 57]

Week 7 Programming Assignment 3
def  snake(M):
  s=[]
  for i in range(len(M)):
    if i%2==0:
      s+=M[i]
    else:
      s+=M[i][::-1]
  return(s) 

Join us :       




Join Now


Previous Year Questions Now to Boost Your Exam Performance

LOADS OF LOGIC