The Joy of Computing using Python | Week 7
Session: JULY-DEC 2023
Course Name: The Joy of Computing using Python
Course Link: Click Here
These are answers of The Joy of Computing using Python Assignment 7 Answers
Q1. Values of CSV files are separated by?
Commas
Colons
Semi-colons
Slash
Answer: Commas
Q2. What is the output of the following code?
1, 2, 3, 7, 11, 10, 9, 5, 6
1, 2, 3, 5, 6, 7, 9, 10, 11
1, 5, 9, 10, 11, 7, 3, 2, 6
1, 5, 9, 2, 6, 10, 3, 7, 11
Answer: 1, 5, 9, 10, 11, 7, 3, 2, 6
Q3. What will be the output of the following code?
Scalar triangle
Right angle triangle
Equilateral triangle
Isosceles triangle
Answer: Equilateral triangle
These are answers of The Joy of Computing using Python Assignment 7 Answers
Q4. Which of the following program will draw a hexagon?
Answer: b

Q5. Which of the following library is used to render data on google maps?
gplot
googlemaps
gmplot
gmeplot
Answer: gmplot
Q6. What is the output of the following code?
Answer:

These are answers of The Joy of Computing using Python Assignment 7 Answers
Q7. Which turtle command is equivalent to lifting up a pen.
penlift()
penup()
uppen()
penremove()
Answer: penup()
These are answers of The Joy of Computing using Python Assignment 7 Answers
Q8. Why do we use functions?
To improve readability.
To reuse code blocks.
For the ease of code debugging.
All of the above
Answer: All of the above
These are answers of The Joy of Computing using Python Assignment 7 Answers
Q9. Library used to import images?
PIL
Imageview
IMG
image
Answer: PIL
These are answers of The Joy of Computing using Python Assignment 7 Answers
Q10. In snakes and ladder what can be the ways to track ladders and snakes?
Maintain a dictionary with snakes or ladder number blocks as keys.
Using the if condition to check on every number.
Both A and B.
None of the above
Answer: Both A and B.
These are answers of The Joy of Computing using Python Assignment 7 Answers
The Joy of Computing using Python Programming Assignmnet
Question 1
Given a sqaure matrix M, write a function DiagCalc which calculate the sum of left and right diagonals and print it respectively.(input will be handled by us)
Input:
A matrix M
[[1,2,3],[3,4,5],[6,7,8]]
Output
13
13
Explanation:
Sum of left diagonal is 1+4+8 = 13
Sum of right diagonal is 3+4+6 = 13
Solution:
def DiagCalc(L):
L_sum=0
R_sum=0
m=L[::-1]
for i in range(len(L)):
for y in range(len(L)):
if i==y:
L_sum+=L[i][y]
R_sum+=m[i][y]
print(L_sum)
print(R_sum,end="")
These are answers of The Joy of Computing using Python Assignment 7 Answers
Question 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]]
Solution:
import numpy
from array import *
def Transpose(M):
arrays = numpy.array(M)
num_list = arrays.transpose().tolist()
return(num_list)
These are answers of The Joy of Computing using Python Assignment 7 Answers
Question 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 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]
Explanation:
For row 1 elements are inserted from left to right
For row 2 elements are inserted from right to left
For row 3 elements are inserted form left to right
and so on
Solution:
def snake(M):
sk=0
sm=[]
for r in M:
m=[]
sk=sk+1
if sk%2==0:
m=r[::-1]
else:
m=r
sm+=m
return(sm)
These are answers of The Joy of Computing using Python Assignment 7 Answers
More Weeks of The Joy of Computing Using Python: Click here
More Nptel Courses: Click here
Session Jan-Apr 2023
Course Name: The Joy of Computing using Python
Course Link: Click Here
These are answers of The Joy of Computing using Python Assignment 7 Answers
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?

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
These are answers of The Joy of Computing using Python Assignment 7 Answers
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
These are answers of The Joy of Computing using Python Assignment 7 Answers
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?

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
These are answers of The Joy of Computing using Python Assignment 7 Answers
Q10. What does the following code snippet in python compute

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
The Joy of Computing using Python Programming Assignmnet
Question 1
Given a sqaure matrix M, write a function 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
Explanation:
Sum of left diagonal is 1+4+8 = 13
Sum of right diagonal is 3+4+6 = 13
Solution:
def DiagCalc(M):
countL = 0
countR = 0
for i in range(len(M)):
countL += M[i][i]
countR += M[i][-1 - i]
print(countL)
print(countR)
n = int(input())
M = []
for i in range(n):
L = list(map(int, input().split()))
M.append(L)
DiagCalc(M)
These are answers of The Joy of Computing using Python Assignment 7 Answers
Question 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]]
Solution:
def Transpose(M):
rowlen = len(M)
collen = len(M[0])
ans = [[] for i in range(collen)]
for i in range(collen):
for j in range(rowlen):
ans[i].append(M[j][i])
return ans
These are answers of The Joy of Computing using Python Assignment 7 Answers
Question 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]
Explanation:
For row 1 elements are inserted from left to right
For row 2 elements are inserted from right to left
For row 3 elements are inserted form left to right
and so on
Solution:
def snake(M):
rowlen = len(M)
collen = len(M[0])
ans = []
for i in range(rowlen):
if i%2 == 0:
for j in M[i]:
ans.append(j)
else:
l = M[i]
for j in range(-1, -collen-1, -1):
ans.append(l[j])
return ans
These are answers of The Joy of Computing using Python Assignment 7 Answers
More Weeks of The Joy of Computing using Python: Click Here
More Nptel courses: https://progiez.com/nptel/
Session JUL-DEC 2022
Course name: The Joy of Computing Using Python
Link to Enroll: Click here
These are answers of The Joy of Computing using Python Assignment 7 Answers
Q1. How ladders & snakes are represented by the instructor?
a. Through lists.
b. Through dictionaries.
c. Through if and elif conditions.
d. Through sets.
Answer: c
Q2. Which of the following is the correct full form of CSV?
a. Comma separated values.
b. Colon separated values.
c. Semi-Colons separated values.
d. Tab separated values.
Answer: a
Q3. Why do we use functions?
a. To improve readability.
b. To reuse code blocks.
c. For the ease of code debugging.
d. For fun.
Answer: a, b, c
These are answers of The Joy of Computing using Python Assignment 7 Answers
Q4. In snakes and ladders, what can be the other ways, except for one used by the instructor, to keep track of ladders and snakes?
a. Maintain a dictionary with snakes or ladder number blocks as keys.
b. Using the if condition to check on every number.
c. Using lists.
d. None of the above
Answer: a, c
Q5. Which of the following libraries is used for animation?
a. Matplotlib
b. Turtle
c. Random
d. PIL
Answer: b
Q6. The spiral animation problem can be broken down into?
a. A list.
b. A 2D table.
c. A 3D table.
d. A dictionary.
Answer: b
These are answers of The Joy of Computing using Python Assignment 7 Answers
Q7. What is the purpose of the GPS program shown in the lectures?
a. To show directions to the user.
b. To track the directions of the user.
c. To show the way to the user on maps.
d. None of the above.
Answer: b
Q8. What does the following program will do after execution?
a. Rename snakesraw.png as snakes.png
b. Make a copy of snakesraw.png with the name snakes.png
c. Make a copy of snakesraw.png with the name snakes.jpeg
d. Throws an error
Answer: d
These are answers of The Joy of Computing using Python Assignment 7 Answers
Q9. Which of the following code will draw a star?

Answer: c
These are answers of The Joy of Computing using Python Assignment 7 Answers
Q10. Which method is used to fill color in shapes drawn by the turtle?
a. color
b. fillcolor
c. changecolor
d. putcolor
Answer: b
These are answers of The Joy of Computing using Python Assignment 7 Answers
Programming Assignment Questions
Question 1
Given a sqaure matrix M, write a function DiagCalc which calculate the sum of left and right diagonals and print it respectively.(input will be handled by us)
Input:
A matrix M
[[1,2,3],[3,4,5],[6,7,8]]
Output
13
13
Solution:
//Code
These are answers of The Joy of Computing using Python Assignment 7 Answers
Question 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]]
Solution:
//Code
These are answers of The Joy of Computing using Python Assignment 7 Answers
Question 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 snake pattern)
Solution:
//Code
These are answers of The Joy of Computing using Python Assignment 7 Answers
More NPTEL Solution: https://progiez.com/nptel

This content is uploaded for study, general information, and reference purpose only.