NPTEL Joy Of Computing Using Python Week 3 Programming Assignment 2025

This article provided the solutions for NPTEL Joy Of Computing Using Python Week 3 Programming Assignment 2025. These programs passed all test cases. So, Come with us to know more about answers.  If you didn't complete the week 3 quiz answers, the link is provided below.

Also Read: NPTEL Joy Of Computing Using Python Week 3 Quiz Answer

NPTEL Joy Of Computing Using Python Week 3 Programming Assignment 2025

NPTEL Joy Of Computing Using Python Week 3 Programming Assignment 2025


Last Date: 13-02-2025

Q1. Create a Python program that finds the second smallest number in a list of positive integers (including zero). The program should prompt the user to input a list of numbers, then compute and print the second smallest number in that list.

Input Format:

  • The input consists of a single list of numbers, separated by spaces.
  • Hint: Use .split() function to convert input to list.

Output Format:

  • The output consists of the second smallest number in the input list. 
Example: 

Input: 3 1 4 1 5 9 2 6 5 3 5 

Output: 2

Program Code: 

def find_second_smallest(numbers):
    unique_numbers = list(set(numbers))  
    if len(unique_numbers) < 2:
        return "No second smallest number available"
    unique_numbers.sort()
    return unique_numbers[1]

numbers = list(map(int, input().split()))

print(find_second_smallest(numbers),end="") {codeBox}

Q2. Create a Python program that removes even duplicate positive integer numbers(includes zero) from a list and prints the unique numbers in the order they first appeared. 

The program should prompt the user to input a list of numbers, then process the list to remove duplicates and print the resulting list of unique numbers.

Input Format:
The input consists of a single list of numbers, separated by spaces.

Output Format:
The output consists of the unique numbers, separated by spaces, from the input list, in the order they first appeared.

Example:
Input:
3 1 4 1 5 9 2 6 5 3 5
Output:
3 1 4 1 5 9 2 6 5 3 5

Program Code:

def remove_even_duplicates(numbers):
    seen = set()
    unique_numbers = []
    for num in numbers:
        if num % 2 != 0 or num not in seen:
            unique_numbers.append(num)
            seen.add(num)
    return unique_numbers

numbers = list(map(int, input().split()))

print(" ".join(map(str, remove_even_duplicates(numbers))),end="") {codeBox}


Q3. Create a Python program that takes a list of integers, reverses the list, adds the values at even indices from both the original and reversed lists, and creates a new list with the result. The new list should be printed in the end.

Input Format:
The input consists of a single list of integers, separated by spaces.

Output Format:
The output consists of the new list of values, separated by spaces, obtained by adding values at even indices from both the original and reversed lists.

Example:
Input:
1 2 3 4 5

Output:
6 2 6 4 6

Program Code:

def process_list(nums):
    reversed_nums = nums[::-1]  
    result = []
    
    for i in range(len(nums)):
        if i % 2 == 0:  # Only consider even indices
            result.append(nums[i] + reversed_nums[i])
        else:
            result.append(nums[i])  
    return result

nums = list(map(int, input().split()))
result = process_list(nums)
print(" ".join(map(str, result)), end="") {codeBox}

Conclusion

For any more Updates or Further Upcoming Assignments, Join the Telegram provided below.

                      👉 CLICK HERE

One Comment Please !

Post a Comment (0)
Previous Post Next Post