Hello everyone, we are came back with Nptel week 6 programming assignment of Joy Of Computing Using Python. In this article we will discuss the answers for week 6 assignment . Please Use these answers as reference, If any doubt arises feel free to comment in the comment section below. Then why Waiting, Come with us, Let us solve the programming assignment. Â
Also Read: Joy of Computing using Python Week 6 Quiz Answers
The Joy Of Computing Using Python Week 6 Programming AssignmentÂ
Before going into the answers of week 6 , let briefly see the what are the topics present in Week 6 :Â
- Substitution Cipher - The Science of Secrecy
- Tic Tac Toe - Down the Memory LaneÂ
- Recursion
Substitution Cipher
A substitution cipher is a method of encrypting a message by replacing each letter of the plaintext with another letter, number, or symbol. The letter-for-letter substitution is based on a predetermined code or key.
Example:Â
A simple substitution cipher might replace every occurrence of the letter "a" with theÂ
letter "x," every "b" with "y," and so on. Using this key, the word "hello" would be encrypted as "uryyb."Â
Tic Tac ToeÂ
Tic Tac Toe is a classic two-player game played on a 3x3 grid. The players take turns placing their symbol (usually X and O) in one of the empty squares, with the objective of getting three of their symbols in a row, either horizontally, vertically, or diagonally. The game is won by the player who successfully gets three of their symbols in a row before the other player, and it is considered a draw if all the squares are filled without any player winning. Tic Tac Toe is a simple yet enjoyable game that can be played anywhere with just a pen and paper or on a computer or mobile device.
Recursion Â
Recursion is a programming technique in which a function calls itself repeatedly until a certain condition is met. This technique allows for the creation of more efficient and concise algorithms for problems that have a repetitive nature.
In a recursive function, the function definition includes a base case and a recursive case. The base case is the condition that stops the recursion and returns a value, while the recursive case is the condition that continues the recursion.
Programming AssignmentÂ
Q1. 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.Â
Program :Â
Â
N=int(input())L=[int(i) for i in input().split()]K=int(input())print(sorted(L).index(L[K-1])+1,end="") {codeBox}
Â
Q2. 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. Â
Program:Â
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+=iprint(ans,end=""){codeBox}
Q3. 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Â
Program:Â
N=int(input())print(sum([i for i in range(N+1)]),end=""){codeBox}
Conclusion:Â
I Request everyone to revisit the website on/before to last date for any re-verification of answers.
Â
If you have any queries, contact us. I am very thankful to answer you.
Â
NOTE:Â I'm answering these questions to the best of my knowledge.