The Joy of Computing using Python | Week 10
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 10 Answers
Q1. What is the output of the following code?
HELLO EVERYONE
Hello Everyone
helloeveryone
hello everyone
Answer: hello everyone
Q2. In flames game when we will stop the iteration over FLAMES?
When only one letter is left in flames.
Only once.
Only the letter remaining times.
None of the above.
Answer: When only one letter is left in flames.
Q3. Output of the following code will be?
hello
h.e.l.l.o
.h.e.l..l.o
.h.e.l.l.o
Answer: .h.e.l..l.o
These are answers of The Joy of Computing using Python Assignment 10 Answers
Q4. Which code snippet represents replacing all vowels with ‘_’ in a string?
Answer: d)

Q5. What will be the output of the following list slicing.
‘Joy of C’
‘ Joy of C’
‘Joy of Co’
‘ Joy of Co’
Answer: ‘ Joy of C’
Q6. What does the following code represent?
Replacing all letters at odd index with ‘_’.
Replacing all vowels at odd index with ‘_’.
Replacing all vowels at even index with ‘_’.
Replacing all letters at even index with ‘_’.
Answer: Replacing all vowels at even index with ‘_’.
These are answers of The Joy of Computing using Python Assignment 10 Answers
Q7. What will be the output of the following code?
[4 6]
[3 7]
[3 4]
None of the above
Answer: [3 7]
Q8. What is the correct way to display the transpose of a matrix?
Answer: b), c)


These are answers of The Joy of Computing using Python Assignment 10 Answers
Q9. Are Lossy and Lossless compressions the same?
Yes, they are identical.
No, they are different.
It depends on the context.
Not enough information provided.
Answer: No, they are different.
These are answers of The Joy of Computing using Python Assignment 10 Answers
Q10. What is the shape of the following numpy array?
numpy.array([ [1,2,3], [4,5,6] ])
(2,3)
(3,2)
(3,3)
(2,2)
Answer: (2,3)
Q11. What will be the output of the following code?
a. [[6 6 6]
[6 6 6]]
b. [[ -7 -7 -17]
[ -6 -26 -16]]
c. [[ 7 7 17]
[ 6 26 16]]
d. [[ 9 11 23]
[14 36 28]]
Answer: c. [[ 7 7 17]
[ 6 26 16]]
These are answers of The Joy of Computing using Python Assignment 10 Answers
The Joy of Computing using Python Programming Assignmnet
Question 1
Given a list L write a program to make a new list to fix the indexes of numbers to in list L to its same value in the new list. Put 0 at remaining indexes. Also print the elements of the new list in the single line. (See explanation for more clarity.)
Input:
[1,5,6]
Output:
0 1 0 0 0 5 6
Explanation:
List L contains 1,5,9 so at 1,5,9, index of new list the respective values are put and rest are initialized as zero.
Solution:
K=[0]*(max(L)+1)
for i in range(len(K)):
if i in L:
K[i]=i
print(*K,end="")
These are answers of The Joy of Computing using Python Assignment 10 Answers
Question 2
Ram shifted to a new place recently. There are multiple schools near his locality. Given the co-ordinates of Ram P(X,Y) and schools near his locality in a nested list, find the closest school. Print multiple coordinates in respective order if there exists multiple schools closest to him. Write a function closestSchool that accepts (X ,Y , L) where X and Y are co-ordinates of Ram’s house and L contains co-ordinates of different school.
Distance Formula(To calculate distance between two co-ordinates): √((X2 – X1)² + (Y2 – Y1)²) where (x1,y1) is the co-ordinate of point 1 and (x2, y2) is the co-ordinate of point 2.
Input:
X, Y (Ram’s house co-ordinates)
N (No of schools)
X1 Y1
X2 Y2
.
.
.
X6 Y6
Output:
Closest pont/points to X, Y
Solution:
def closestSchool(x, y, L):
min=9999999
distance=list()
for ij in L:
dis=((x-ij[0])**2+(y-ij[1])**2)**0.5
distance.append(dis)
if dis<min:
min=dis
for ij in range(len(distance)):
if distance[ij]==min:
print(L[ij])
These are answers of The Joy of Computing using Python Assignment 10 Answers
Question 3
Given a string s write a program to convert uppercase letters into lowercase and lowercase letters into uppercase. Also print the resultant string.
Note: You need to talk the input and do not print anything while taking input.
Input:
The Joy Of Computing
Output
tHE jOY oF cOMPUTING
Solution:
print(input().swapcase(),end='')
These are answers of The Joy of Computing using Python Assignment 10 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 10 Answers
Q1. Which math problem flames is related to?
a. kadane’s problem
b. Josephus problem
c. Conjecture Collatz
d. Dijkstra Problem
Answer: b. Josephus problem
Q2. What will be the output of the following list slicing.

a. ‘Joy of C’
b. ‘ Joy of C’
c. ‘Joy of Co’
d. ‘ Joy of Co’
Answer: b. ‘ Joy of C’
These are answers of The Joy of Computing using Python Assignment 10 Answers
Q3. What will be the output of the following program?

a. I zm zmzzed
b. I zm zmazed
c. I am zmzzed
d. I am amazed
Answer: d. I am amazed
Q4. What are the consequences of image compression?
a. Less size
b. Lower quality
c. More size
d. Higher quality
Answer: a, b
These are answers of The Joy of Computing using Python Assignment 10 Answers
Q5. what is the output of the following code?

a. [[ 1 2 3 4]
[ 5 6 7 8]
[ 9 10 11 12]]
b. [[ 1 2 3]
[ 4 5 6]
[ 7 8 9]
[10 11 12]]
c. Error
d. [[1,2,3,4,5,6]
[7, 8, 9, 10, 11, 12]]
Answer: a. [[ 1 2 3 4]
[ 5 6 7 8]
[ 9 10 11 12]]
Q6. What will be the output of the following code?

a. [4 6]
b. [3 7]
c. [3 4]
d. None of the above
Answer: b. [3 7]
These are answers of The Joy of Computing using Python Assignment 10 Answers
Q7. Amongst which of the following is / are the method of list?
a. append()
b. extend()
c. insert()
d. All of the mentioned above
Answer: d. All of the mentioned above
Q8. The output of the following program will be?

a. Pynhon
b. Pnthon
c. Python
d. Error
Answer: d. Error
These are answers of The Joy of Computing using Python Assignment 10 Answers
Q9. Which of the following is not a method in string?
a. lower()
b. upper()
c. isalpha()
d. insert()
Answer: d. insert()
Q10. What is the output of the following code?

a. HELLO EVERYONE
b. Hello Everyone
c. helloeveryone
d. hello everyone
Answer: d. hello everyone
These are answers of The Joy of Computing using Python Assignment 10 Answers
The Joy of Computing using Python Programming Assignmnet
Question 1
Given a list L write a program to make a new list and match the numbers inside list L to its respective index in the new list. Put 0 at remaining indexes. Also print the elements of the new list in the single line. (See explanation for more clarity.)
Input:
[1,5,6]
Output:
0 1 0 0 0 5 6
Explanation:
List L contains 1,5,9 so at 1,5,9, index of new list the respective values are put and rest are initialized as zero.
Solution:
L = list(map(int, input().split()))
m = max(L)
L1 = [0]*(m+1)
for i in L:
L1[i] = i
for i in range(len(L1)-1):
print(L1[i], end=' ')
print(L1[-1])
These are answers of The Joy of Computing using Python Assignment 10 Answers
Question 2
Ram shifted to a new place recently. There are multiple schools near his locality. Given the co-ordinates of Ram P(X,Y) and schools near his locality in a nested list, find the closest school. Print multiple coordinates in respective order if there exists multiple schools closest to him. Write a function closestSchool that accepts (X ,Y , L) where X and Y are co-ordinates of Ram’s house and L contains co-ordinates of different school.
Distance Formula(To calculate distance between two co-ordinates): √((X2 – X1)² + (Y2 – Y1)²) where (x1,y1) is the co-ordinate of point 1 and (x2, y2) is the co-ordinate of point 2.
Input:
X, Y (Ram’s house co-ordinates)
N (No of schools)
X1 Y1
X2 Y2
.
.
.
X6 Y6
Output:
Closest pont/points to X, Y
Solution:
def closestSchool(x,y,L):
min = 99999
distance = []
for i in L:
dis=((x-i[0])**2+(y-i[1])**2)**0.5
distance.append(dis)
if dis<min:
min = dis
for i in range(len(distance)):
if distance[i]==min:
print(L[i])
These are answers of The Joy of Computing using Python Assignment 10 Answers
Question 3
Given a string s write a program to convert uppercase letters into lowercase and lowercase letters into uppercase. Also print the resultant string.
Note: You need to talk the input and do not print anything while taking input.
Input:
The Joy Of Computing
Output
tHE jOY oF cOMPUTING
Solution:
s = input()
ns =''
for i in range(len(s)):
if s[i].isupper():
ns = ns+s[i].lower()
elif s[i].islower():
ns = ns+s[i].upper()
else:
ns += s[i]
print(ns)
These are answers of The Joy of Computing using Python Assignment 10 Answers
More Weeks of The Joy of Computing using Python: Click Here
More Nptel courses: http://13.235.254.184/nptel/
