NPTEL Joy Of Computing Using Python Week 10 Programming Answers

Hey Folks, Hope you are doing well. In this article i am providing the solutions for week 10 Joy of Computing Using Python Programming Answers. In the Previous article i discussed about the Quiz answers of week 10 and week 11. Then Come with us until the last to know more about this week 10 programming. 

Also Read: Joy Of Computing Week 11 Quiz Answers

Also Read: Joy of Computing Week 10 Quiz Answers

NPTEL Joy Of Computing Using Python


NPTEL Joy Of Computing Using Python Week 10 Programming Answers  

Last Date: 05-10-2023

Q1. 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.

Program Code:

K=[0]*(max(L)+1)
for i in range(len(K)):
  if i in L:
    K[i]=i
print(*K,end="")  {codeBox}

Q2. 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

Program Code:

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])  {codeBox}

Q3. 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

Program Code:

print(input().swapcase(),end='') {codeBox}

Conclusion

If any change in the answers visit the website on or before to the last Date. 

Join the telegram channel for more updates 👉 CLICK HERE 




One Comment Please !

Post a Comment (0)
Previous Post Next Post