Joy Of Computing Using Python Week 6 Programming Assignment

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


Joy Of Computing Using Python Week 6 Programming Assignment

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+=i
print(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.



One Comment Please !

Post a Comment (0)
Previous Post Next Post