The Joy of Computing Using Python NPTEL Assignment 6 Answers

Are you looking for The Joy of Computing Using Python NPTEL Week 6 Answers? You’ve come to the right place! Access the latest and most accurate solutions for your Assignment 6 in The Joy of Computing Using Python course

Course Link: Click Here


The Joy of Computing Using Python NPTEL Week 6 Answers (July-Dec 2024)
The Joy of Computing Using Python NPTEL Week 6 Answers (July-Dec 2024)

The Joy of Computing Using Python NPTEL Week 6 Answers (July-Dec 2024)


1. If n is a positive integer, what is the output of the function given input n,

Sum of numbers from 1 to n
Sum of numbers from 1 to n-1
n-1
n

Answer: n


2. Which of the following are true about recursion?
Recursion is a process in which a function calls itself as a subroutine.
Recursion is a better alternative for performing repetitive tasks compared to iteration.
Recursion requires more resources compared to iteration.

Answer: Recursion is a process in which a function calls itself as a subroutine.
Recursion requires more resources compared to iteration.


3. What is the output of following code ?

10
8
5
Error

Answer: 8


4. The letter ‘e’ is the most frequently occurring letter in the English language. Suppose we apply a Substitution Cipher where ‘e’ is mapped to ‘a’, and all other letters are uniquely mapped to different letters. If we encrypt a very long English storybook using this cipher, will the frequency of ‘a’ be the highest in the encrypted text?

Hint: Search the internet for more info, if needed
Yes, it would be same as ’e’ in the original text
Yes, it would be higher than ’e’ in the original text.
No, it would be lower than ’e’ in the original text.
No, we cannot predict

Answer: Yes, it would be same as ’e’ in the original text


5. Could we check frequency of letters in a long ciphertext and map them to frequency of letters in English to decrypt the message?

Hint: Search the internet for more info, if needed.
Yes, it is possible.
No, it is not possible.

Answer: Yes, it is possible.


6. What are drawbacks of using frequency analysis to decrypt a message that has been encrypted using Substitution Cipher?
It will not work if the cipher text is too small.
It works flawlessly.
It will not work if the encrypted text was previously encrypted using a different cipher, which could have removed patterns in common English.
The frequency analysis method doesn’t work at all for Substitution Cipher

Answer: It will not work if the cipher text is too small.
It will not work if the encrypted text was previously encrypted using a different cipher, which could have removed patterns in common English.


7. If variable dict name is a non-empty dictionary, what does dict name.keys() return?
Returns nothing, but prints all the keys in the dictionary.
Returns a list of all the keys in the dictionary.
Returns a list of all the values in the dictionary.
Returns a list of all the items in the dictionary

Answer: Returns a list of all the keys in the dictionary.


8. Is Ceaser Cipher a type of Substitution Cipher?
Yes
No

Answer: Yes


9. What is the consequence of not having a base case in a recursive function?
The function will run infinitely.
The function will run only once.
The function will not run at all.
The function will run only for a fixed number of times.

Answer: The function will run infinitely.


10. What are the number of possible final lines when someone wins, in a game of TicTac-Toe?
3
8
9
4

Answer: 8


All Weeks of The Joy of Computing Using Python: Click here

For answers to additional Nptel courses, please refer to this link: NPTEL Assignment Answers


The Joy of Computing Using Python NPTEL Week 6 Answers (JAN-APR 2024)

Course Name:  The Joy of Computing using Python

Course Link: Click Here

For answers or latest updates join our telegram channel: Click here to join

These are the Joy of Computing using Python Assignment 6 Answers


Q1. What is the output of following code:
14930352
75025
610
None of the above

Answer: 75025


Q2. Which method in Python is used to convert lowercase letters in a string to uppercase?
upper()
capitalize()
casefold()
swapcase()

Answer: upper()


For answers or latest updates join our telegram channel: Click here to join

These are the Joy of Computing using Python Assignment 6 Answers


Q3. The “Min Max” strategy, often referred to as the minimax algorithm, is a decision-making algorithm used in game theory and artificial intelligence. It’s commonly employed in two-player games with alternate turns and perfect information, such as chess or tic-tac-toe. What is the primary objective of the min max algorithm?
Maximizing the player’s score
Minimizing the opponent’s score
Minimizing the maximum possible loss
Maximizing the number of moves

Answer: Minimizing the maximum possible loss


Q4. Typecasting refers to the conversion of one data type to another. Python provides several built-in functions for typecasting, such as int(), float(), str(), list(), tuple(), set(), and dict() among others, to convert between different data types. What would be the output of the following code?
123
ValueError
SyntaxError
NameError

Answer: ValueError


For answers or latest updates join our telegram channel: Click here to join

These are the Joy of Computing using Python Assignment 6 Answers


Q5. What term is used in programming languages when a function calls itself?
Self-referencing
Iteration
Recursion
Circular referencing

Answer: Recursion


Q6. Consider the following snippet of code.
If L is a non-empty list of positive integers, which of the following statements is correct about the recursive function func(L)?

It returns the total number of odd elements in the list L
It returns the total number of even elements in the list L
It returns the sum of the even elements in the list L
It returns the sum of the odd elements in the list L

Answer: It returns the total number of even elements in the list L


For answers or latest updates join our telegram channel: Click here to join

These are the Joy of Computing using Python Assignment 6 Answers


Q7. Consider the following snippet of code.
If L is a non-empty list of positive integers, which of the following statements is correct about the recursive function func(L)?

It returns the total number of odd elements in the list L
It returns the total number of even elements in the list L
It returns the sum of the even elements in the list L
It returns sum of the odd elements in the list L

Answer: It returns sum of the odd elements in the list L


Q8. What purpose does a base case serve in recursive functions?
To make the function run faster
To eliminate the need for additional functions
To prevent infinite recursion and ensure termination
To enable the function to handle complex calculations

Answer: To prevent infinite recursion and ensure termination


For answers or latest updates join our telegram channel: Click here to join

These are the Joy of Computing using Python Assignment 6 Answers


Q9. What is the value returned by f(10000)?

Answer: 7


Q10. What is the value returned by f(-8)?

Answer: 5


For answers or latest updates join our telegram channel: Click here to join

These are the Joy of Computing using Python Assignment 6 Answers


Programming Assignment

Question 1

The distance between two letters in the English alphabet is one more than the number of letters between them. Alternatively, it can be defined as the number of steps needed to move from the alphabetically smaller letter to the larger letter. This is always a non-negative integer. For example:
The distance between two words is defined as follows:
It is -1, if the words are f unequal lengths.
If the word-lengths are equal, it is the sum of the distances between letters at corresponding positions in the words. For example:
​dword​(dog,cat)=dletter​(d,c)+dletter​(o,a)+dletter​(g,t)=1+14+13=28

Write a function named distance that accepts two words as arguments and returns the distance between them.
You do not have to accept input from the user or print output to the console. You just have to write the function definition.

Solution:

def distance(word1, word2):
  if len(word1) != len(word2):
    return(-1)

  dis = 0
  for i in range(len(word1)):
    dis += abs(ord(word1[i]) - ord(word2[i]))

  return(dis)

For answers or latest updates join our telegram channel: Click here to join

These are the Joy of Computing using Python Assignment 6 Answers


Question 2

P is a dictionary of father-son relationships that has the following structure: for any key in the dictionary, its corresponding value is the father of key.

Solution:

def ancestry(P, present, past):
  if present == past:
    return([present])

  if present not in P:
    return(None)
  ancestral_chains = ancestry(P, P[present], past)
  if ancestral_chains:
    return([present] + ancestral_chains)
  return(None)

For answers or latest updates join our telegram channel: Click here to join

These are the Joy of Computing using Python Assignment 6 Answers


Question 3

Fibonacci is a young resident of the Italian city of Pisa. He spends a lot of time visiting the Leaning Tower of Pisa, one of the iconic buildings in the city, that is situated close to his home. During all his visits to the tower, he plays a strange game while climbing the marble steps of the tower.
You do not have to accept input from the user or print output to the console. You just have to write the function definition.

Solution:

def steps(n):
  if n <= 0:
    return 0
  elif n == 1:
    return 1
  elif n == 2:
    return 2
  elif n == 3:
    return 4
  one_steps = steps(n-1)
  two_steps = steps(n-2)
  three_steps = steps(n-3)
  return(one_steps + two_steps + three_steps)

For answers or latest updates join our telegram channel: Click here to join

These are 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


The Joy of Computing Using Python NPTEL Week 6 Answers (July-Dec 2023)

Course Name:  The Joy of Computing using Python

Course Link: Click Here

These are 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 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 the Joy of Computing using Python Assignment 6 Answers