The Joy of Computing using Python | Week 6
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 6 Answers
Q1. What will be the output of the following code?
Shift every letter in a given word by value.
Shift every letter in a given word by 1.
Shift every letter in a given word by 26.
Returns the same word.
Answer: Shift every letter in a given word by value.
Q2. In the list L = [4,6,7,4,6,2,1], What is the index of element ‘7’?
0
1
2
3
Answer: 2
Q3. Which of the following is true about recursion?
Recursion always performs better than non-recursive code.
Recursive code is easier to debug.
The base case is necessary for recursion.
Recursive code can be shorter than non-recursive code
Answer: b, c, d
These are answers of The Joy of Computing using Python Assignment 6 Answers
Q4. What will be the output of the following program?
Calculating sum of first n terms.
Calculating product of first n terms.
Calculating power of first n terms.
Calculating sum of last n terms.
Answer: Calculating product of first n terms.
Q5. In Caesar cipher,the mediator needs to make maximum of how many trails to break the code?
1
26
no trail needed
10
Answer: 26
Q6. What is the output of the following program?
3628800
Runs into an infinite loop
55
Syntax error
Answer: Runs into an infinite loop
These are answers of The Joy of Computing using Python Assignment 6 Answers
Q7. What’s the correct code for Binary search?
Answer: c

These are answers of The Joy of Computing using Python Assignment 6 Answers
Q8. Which of the following is TRUE about MIN-MAX strategy?
Maximize the chances of your winning and minimize the changes of the opponent winning
The game with min-max strategy can never be drawn
Minimize the chances of your winning and maximize the chances of the opponent winning
All the above are true
Answer: Maximize the chances of your winning and minimize the changes of the opponent winning
These are answers of The Joy of Computing using Python Assignment 6 Answers
Q9. A program that is written recursively cannot be written in a non-recursive manner.
True
False
Answer: False
These are answers of The Joy of Computing using Python Assignment 6 Answers
Q10. what will be the output of the following program?
Answer:
**********
********
******
****
**
*
These are answers of The Joy of Computing using Python Assignment 6 Answers
The Joy of Computing using Python Programming Assignmnet
Question 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
Explanation:
The position of aman’s favourite planet in unsorted list is 2 and list of distances of planets at position 2 the distance is 5. After sorting the list [1,2,3,4,5] the position of aman’s favourite is changed to 5.
Note: Index is different from position. Indexing of the list starts from 0 whereas positioning in the list start form 1.
Solution:
print(sorted(L).index(L[K-1])+1+0,end="")
These are answers of The Joy of Computing using Python Assignment 6 Answers
Question 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 small letter in the sentence by -2 position and every capital 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 which 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
Explanation
H is shifted by -3 position and changed to E. ‘e’ is shifted by -2 position and changed to c and so on.
Solution:
Cap1=list("ABCDEFGHIJKLMNOPQRSTUVMWXYZ")
Small=list('abcdefghijklmnopqrstuvwxyz')
ans=""
for a in S:
if a=='a':
ans+='y'
elif a=='b':
ans+='z'
elif a=='A':
ans+='X'
elif a=='B':
ans+='Y'
elif a=='C':
ans+='Z'
elif a=='W':
ans+='T'
else:
if a in Cap1:
ans+=Cap1[Cap1.index(a)-3]
elif a in Small:
ans+=Small[Small.index(a)-2]
else:
ans+=a
print(ans,end="")
These are answers of The Joy of Computing using Python Assignment 6 Answers
Question 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
Explanation
Sum of first 3 natural numbers are 0+1+2+3 = 6
Solution:
def whole(n):
if n==0:
return 0
else:
return n+whole(n-1)
These are answers of The Joy of Computing using Python Assignment 6 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 6 Answers
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)
These are answers of The Joy of Computing using Python Assignment 6 Answers
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
These are answers of The Joy of Computing using Python Assignment 6 Answers
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.
These are answers of The Joy of Computing using Python Assignment 6 Answers
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.
The Joy of Computing using Python Programming Assignmnet
Question 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
Explanation:
The position of aman’s favourite planet in unsorted list is 2 and list of distances of planets at position 2 the distance is 5. After sorting the list [1,2,3,4,5] the position of aman’s favourite is changed to 5.
Note: Index is different from position. Indexing of the list starts from 0 whereas positioning in the list start form 1.
Solution:
N = int(input())
L = [int(i) for i in input().split()]
K = int(input())
position = L[K-1]
L.sort()
for i in range(N):
if L[i] == position:
print(i+1)
break
These are answers of The Joy of Computing using Python Assignment 6 Answers
Question 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
Explanation
H is shifted by -3 position and changed to E. ‘e’ is shifted by -2 position and changed to c and so on.
Solution:
S = input()
import string
low = string.ascii_lowercase
cap = string.ascii_uppercase
ans = ''
for i in S:
if i in low:
index = low.index(i)
index = ((index-2)+26)%26
ans+=low[index]
elif i in cap:
index = cap.index(i)
index = ((index-3)+26)%26
ans+=cap[index]
else:
ans+=i
print(ans)
These are answers of The Joy of Computing using Python Assignment 6 Answers
Question 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
Explanation
Sum of first 3 natural numbers are 0+1+2+3 = 6
Solution:
def whole(n):
if n==0:
return 0
else:
return n+whole(n-1)
N = int(input())
print(whole(N))
These are answers of The Joy of Computing using Python Assignment 6 Answers
More Weeks of The Joy of Computing using Python: Click Here
More Nptel courses: https://progiez.com/nptel/
Session JUL-DEC 2022
Course name: The Joy of Computing Using Python
Link to Enroll: Click here
These are answers of The Joy of Computing using Python Assignment 6 Answers
Q1. 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
Q2. Which of the following is true about recursion?
a. Recursion always performs better than non-recursive code.
b. Recursive code is easier to debug
c. The base case is necessary for recursion.
d. Recursive code can be shorter than non-recursive code.
Answer: b, c, d
These are answers of The Joy of Computing using Python Assignment 6 Answers
Q3. What will be the output of the following program?
Answer: b
Q4. What will be the output of the following program?
Answer: a
Q5. What’s the correct code for Binary search?
Answer: c
These are answers of The Joy of Computing using Python Assignment 6 Answers
Q6. Which of the following can be used to see the dimension of a NumPy array named ‘arr’?
a. dim(arr)
b. shape(arr)
c. arr.shape
d. arr.shape()
Answer: c
Q7. If PYTHON is encoded by TCXLSR then DIAMOND will be encoded as?
a. EJBNPOE
b. FKCORPF
c. HMERTSH
d. HMEQSRH
Answer: d
These are answers of The Joy of Computing using Python Assignment 6 Answers
8. Select the correct statement
1) print(‘9a’.isalnum()) will return True.
2) ‘9a’ contains both alphabetic and numeric parts.
a. Option 1 is correct, option 2 is correct. Option 2 is the correct explanation for option 1.
b. Option 1 is correct, option 2 is incorrect.
c. Option 1 is correct, option 2 is correct. Option 2 is not the correct explanation for option 1.
d. Option 1 is incorrect, option 2 is incorrect.
Answer: a
Q9. What will be the output of the following program?
a. A dictionary with the count of each character in s.
b. A dictionary with the count of each special character in s.
c. A dictionary with the count of letters in s.
d. Error
Answer: d
These are answers of The Joy of Computing using Python Assignment 6 Answers
Q10. 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
These are answers of The Joy of Computing using Python Assignment 6 Answers
Programming Assignment Questions
Question 1
Given a list L containing integers, write a program that creates and prints a dictionary ‘d’ containing all the numbers that occur twice or more in the list as keys and their indexes as values. Both the keys are and their values should be in the same order as given the list.
You have to take the input.
Input
List
Output
Dictionary D
Solution:
//Code
These are answers of The Joy of Computing using Python Assignment 6 Answers
Question 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 small letter in the sentence by -2 position and every capital 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 which prints the encrypted message. You can assume there are no special characters except spaces and numeric value.
Input
A string S
Output
Encrypted string
Solution:
//Code
These are answers of The Joy of Computing using Python Assignment 6 Answers
Question 3
Take a string S as an input and print ‘palindrome’ if string S is a palindrome or ‘not palindrome’ if string S is not a palindrome.
A palindrome is a word which spells same from forward and backward. Example DAD.
Input
A string S
Output:
palindrome or not palindrome
Solution:
//Code
These are answers of The Joy of Computing using Python Assignment 6 Answers
More NPTEL Solution: https://progiez.com/nptel

This content is uploaded for study, general information, and reference purpose only.