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

ABOUT THE COURSE :

Week 10
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 10 Assignment Solutions :-

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.
Week 10 2

a)  ‘Joy of C’
b) ‘ Joy of C’
c) ‘Joy of Co’
d) ‘ Joy of Co’

Answer :- (b) ‘ Joy of C’ 

Q3) What will be the output of the following program?
Week 10 3

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) 

Q5) What is the output of the following code?
WEek 10 5

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) 

Q6) What will be the output of the following code?
Week 10 6
a)  [4 6]
b) [3 7]
c) [3 4]
d) None of the above

Answer :- (b) [3 7] 

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?
Week 10 8
a)  Pynhon
b) Pnthon
c) Python
d) Error

Answer :- (d) Error 

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?
week 10 10
a) HELLO EVERYONE
b) Hello Everyone
c) helloeveryone
d) hello everyone

Answer :- (d) hello everyone 

 Week 10 Programming Assignment 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
Week 10 Programming Assignment 1
L=[int(i) for i in input().split()]
ans=[0]*(max(L)+1)
for i in range(len(ans)):
  if i in L:
    ans[i]=i
print(*ans,end="")  

 Week 10 Programming Assignment 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
Week 10 Programming Assignment 2
def closestSchool(x, y, L):
  min=999466
  distance=[]
  for a in L: 
    dis=((x-a[0])**2+(y-a[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])

 Week 10 Programming Assignment 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
Week 10 Programming Assignment 3
s=input()
print(s.swapcase(),end="")

Join us :