The Joy of Computing using Python | NPTEL 2023 | Week 6 Assignment Solutions
ABOUT THE COURSE :
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 6 Assignment Solutions :-
Q1) Which of the following is true about recursion?
a) Recursion always performs better than non-recursive code.
b) Recursive code can be reused.
c) The base case is necessary for recursion.
d) Recursive code can be shorter than non-recursive code
Answer :- (b), (c), (d)
Q2) If PYTHON is encoded by TCXLSR then DIAMOND will be encoded as?
a) EJBNPOE
b) FKCORPF
c) HMERTSH
d) HMEQSRH
Answer :- (d) HMEQSRH
Q3) Let L be a list containing different names of movies. Which statement is correct to select a random movie name from that list L?
a) random.choices(L)
b) random.select(L)
c) random.movie(L)
d) random.random(L)
Answer :-
(a) random.choices(L)
Q4) In the list L = [4,6,7,4,6,2,1], What is the index of element ‘7’?
a) 0
b) 1
c) 2
d) 3
Answer :- (c) 2
Q5)What will be the output of the following code?
a) Shift every letter in a given word by value.
b) Shift every letter in a given word by 1.
c) Shift every letter in a given word by 26.
d) Returns the same word.
Answer :- (a) Shift every letter in a given word by value.
Q6) Library used to import images?
a) PIL
b) Imageview
c) IMG
d) image
Answer :- (a) PIL
Q7) Values of CSV files are separated by?
a) Commas
b) Colons
c) Semi-colons
d) Slash
Answer :- (a) Commas
Q8) what will be the output of the following program?
a) **********
*********
********
*******
******
*****
****
***
**
*
b) *********
*******
*****
***
*
c) Runs into infinite loop
d) **********
********
******
****
**
*
Answer :- (d)
Q9) What will happen if we don’t check for a base case in recursion.
a) The program will run smoothly
b) The program will return a wrong output.
c) The program will enter into an infinite loop.
d) The program will never run.
Answer :- (c) The program will enter into an infinite loop.
Q10)Which of the following is true about recursion?
a) Recursion increases the speed of the program.
b) Recursion decreases the speed of the program.
c) Speed of the program remains the same.
d) Recursion is easier to understand than non-recursive programs.
Answer :- (b) Recursion decreases the speed of the program.
Week 6 Programming Assignment 1 :-
Aman likes to study about planets. Every night he goes outside and observe some planets with his telescope. Then he guesses the distance of each planet and pen it down. In this process he also pen down his favourite planet position. Given the distance of each planet to be unique you need to return position of Aman's favourite planet after sorting all the distances.
Input:
N (No of planets)
L (List of distances of planet)
K (position of Aman's favourite planet in unsorted list)
Output:
Position of Aman's favourite planet in sorted List.
Example:
Input
5
[4,5,3,2,1]
2
Output
5
Week 6 Programming Assignment 1
n=int(input()) l=input() l=l.split(' ') list=[] for i in l: list.append(int(i)) k=int(input()) a=list[k-1] list.sort() print(list.index(a)+1,end='')
Week 6 Programming Assignment 2 :-
Romeo and Juliet love each other. Romeo wants to send a message to Juliet and also don't want anyone to read it without his permission. So, he shifted every lower-case letter in the sentence by -2 position and every upper-case letter by -3 position. (If the letter is c, after shifting to by -2 position it changes to a, and for D new letter will be A).But the letter is too long, and Romeo does not have enough time to encrypt his whole letter. Write a program to help Romeo that prints the encrypted message. You can assume there are no special characters except spaces and numeric value.
Input
A string S
Output
Encrypted string
Example
Input
Hello Juliet
Output
Ecjjm Gsjgcr
Week 6 Programming Assignment 2
A=input() ans=str() for i in A: if i.islower(): if i=='a': ans+='y' elif i=='b': ans+='z' else: ans+=chr(ord(i)-2) elif i.isupper(): if i=='A': ans+='X' elif i=='B': ans+='Y' elif i=='C': ans+='Z' else: ans+=chr(ord(i)-3) elif i.isspace() or i.isnumeric(): ans+=i print(ans,end="")
Week 6 Programming Assignment 3 :-
Write a function whole(N) which takes a number N and return the sum of first N whole number. Write the program using recursion.
Input
N
Output
sum of whole numbers till N
Example:
Input
3
Output
6
Week 6 Programming Assignment 3
N=int(input()) print(sum([i for i in range(N+1)]),end="")
Follow Us