NPTEL Joy Of Computing Using Python Week 6 Programming Assignment 2025

This article describes NPTEL Joy Of Computing Using Python Week 5 Programming Assignment 2025. If you didn't complete the assignment for Week 5 Programming, the link is provided below. Also, join the telegram for updated answers every week.


Join us on Telegram 👉 CLICK HERE 

NPTEL Joy Of Computing Using Python Week 5 Programming Assignment 2025

NPTEL Joy Of Computing Using Python Week 6 Programming Assignment 2025

Q1. The Treasure Hunt

You are part of an elite team of treasure hunters, and your latest mission is to find the hidden treasure in a mysterious ancient temple. Inside the temple, you discover a series of enchanted scrolls containing arrays of magical numbers. The numbers are encrypted in different arrays, and each scroll has a clue indicating which element in the array holds the key to the treasure.

You are given one of these arrays, and the clue on the scroll tells you that the treasure is hidden inside the kth smallest number in that array. Your task is to figure out the kth smallest number from the array, where k is smaller than the size of the array, and return it as your answer.

The treasure hunters in your team trust you with this task, and the sooner you find the key, the sooner they can open the vault. So, be efficient and find the answer quickly!

Example:

Imagine the scroll has the following magical array: 12 3 5 7 19 17 4
And the clue tells you that k = 4.

Your mission is to find the 4th smallest number in the array. Upon scanning the array, you discover that the 4th smallest number is 7.

 Input:

A list of n integers
An integer k (where k <= n).

Output:

Return the kth smallest element from the array.
If k > n, then generate an error message, ‘The clue k should be smaller than or equal to the list size’

Program Code: 

magic_array=[int(i) for i in input().split()]
k=int(input())
if k<=len(magic_array):
print(sorted(magic_array)[k-1],end="")
else:
    print("The clue k should be smaller than or equal to the list size",end="") {codeBox}


Q2. The Binary Quest

Alex, a young programmer, discovered a challenge: Convert a decimal number to binary using recursion! The rules were simple—no loops, no built-in functions —only the magic of recursion.

 Steps to convert a decimal number to binary:
  • Divide the number by 2.
  • Store the remainder (0 or 1).
  • Repeat with the quotient until it becomes 0.
  • Read the remainders in reverse order to get the binary number.
For example, Consider a decimal number 13

13 ÷ 2 = 6, remainder 1
 6 ÷ 2 = 3, remainder 0
 3 ÷ 2 = 1, remainder 1
 1 ÷ 2 = 0, remainder 1

Binary: 1101 (reading from bottom to top)

 Input Format: A positive integer, n

13

Output Format: Binary number

1101

Program Code: 

def decimal_to_binary(n):
    if n == 0:
        return ""
    return decimal_to_binary(n // 2) + str(n % 2)

# Input
n = int(input())
binary_result = decimal_to_binary(n)
print(binary_result if binary_result else "0", end=''){codeBox}


Q3. Removing an element Recursively:

Write a recursive function delete_elements in Python that removes all occurrences of a specified item from a list, creating and returning a new list without modifying the input list.

Example :

Input:

A list of integers (can contain duplicates)
An integer item which represents the element to be removed from the list.

4 5 6

4

Output:

Original list

A new list with all occurrences of the item removed.

4 5 6

5 6

Program Code: 

def delete_elements(lst, item):
    if not lst:
        return lst
    return delete_elements(lst[1:], item) if lst[0] == item else [lst[0]] + delete_elements(lst[1:], item){codeBox}




Conclusion 

For Faster Updates and Immediate answers links, join us on Telegram

Join us on Telegram 👉 CLICK HERE











One Comment Please !

Post a Comment (0)
Previous Post Next Post