The Joy of Computing using Python | Week 10

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.

image 16

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?

image 17

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?

image 18

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?

image 19

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?

image 20

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?

image 21

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: https://progiez.com/nptel/



These are answers of The Joy of Computing using Python Assignment 10 Answers