NPTEL The Joy of Computing Using Python Week5 Assignment 2024

NPTEL-The-Joy-of-Computing-Using-Python-Week5-Assignment-2024

NPTEL Course a fun filled whirlwind tour of 30 hrs, covering everything you need to know to fall in love with the most sought after skill of the 21st century. The course brings programming to your desk with anecdotes, analogies and illustrious examples. Turning abstractions to insights and engineering to art, the course focuses primarily to inspire the learner’s mind to think logically and arrive at a solution programmatically. As part of the course, you will be learning how to practice and culture the art of programming with Python as a language. At the end of the course, we introduce some of the current advances in computing to motivate the enthusiastic learner to pursue further directions. The Joy of Computing using python is a fun filled course offered by NPTEL.

The Joy Of Computing Using Python Week5 Assignment Jan 2024

INTENDED AUDIENCE :  Any interested audience
PREREQUISITES :  10th standard/high school
INDUSTRY SUPPORT :  Every software company is aware of the potential of a first course in computer science. Especially of a first course in computing, done right.

Course Layout

  • Motivation for Computing
  • Welcome to Programming!!
  • Variables and Expressions : Design your own calculator
  • Loops and Conditionals : Hopscotch once again
  • Lists, Tuples and Conditionals : Lets go on a trip
  • Abstraction Everywhere : Apps in your phone
  • Counting Candies : Crowd to the rescue
  • Birthday Paradox : Find your twin
  • Google Translate : Speak in any Language
  • Currency Converter : Count your foreign trip expenses
  • Monte Hall : 3 doors and a twist
  • Sorting : Arrange the books
  • Searching : Find in seconds
  • Substitution Cipher : What’s the secret !!
  • Sentiment Analysis : Analyse your Facebook data
  • 20 questions game : I can read your mind
  • Permutations : Jumbled Words
  • Spot the similarities : Dobble game
  • Count the words : Hundreds, Thousands or Millions.
  • Rock, Paper and Scissor : Cheating not allowed !!
  • Lie detector : No lies, only TRUTH
  • Calculation of the Area : Don’t measure.
  • Six degrees of separation : Meet your favourites
  • Image Processing : Fun with images
  • Tic tac toe : Let’s play
  • Snakes and Ladders : Down the memory lane.
  • Recursion : Tower of Hanoi
  • Page Rank : How Google Works !!

Programming Assignment 1

Question 1 : Write a function insert that accepts a sorted list L of integers and an integer x as input. The function should return a sorted list with the element x inserted at the right place in the input list. The original list should not be disturbed in the process.

1)     The only built-in methods you are allowed to use are append and remove. You should not use any other method provided for lists.

2)     You do not have to accept input from the user or print output to the console. You just have to write the function definition.

				
					def insert(L, x):
    """
    insert an element x into a sorted list L

    Arguments:
        L: list
        x: integers
    Return:
        sorted_L: list
    """
    
    sorted_L = L[:]
    
    for i in range(len(sorted_L)):
        if sorted_L[i] > x:
            sorted_L.insert(i, x)
            return sorted_L
    
    sorted_L.append(x)
    return sorted_L
				
			

Programming Assignment 2

Question 2Accept a sequence of words as input. Create a dictionary named real_dict whose keys are the letters of the English alphabet. For each key (letter), the corresponding value should be a list of words that begin with this key (letter). For any given key, the words should be appended to the corresponding list in the order in which they appear in the sequence. You can assume that all words of the sequence will be in lower case.

				
					input_words = input().split(",")
real_dict={}
for word in input_words:
    first_char = word[0]
    if first_char not in real_dict:
        real_dict[first_char] = []
    real_dict[first_char].append(word)

				
			

Programming Assignment 3

Question 3Consider a grid-world of size n×n. You are at the bottom-left corner, at the cell (1,1), to start with. A sample grid-world for the case of n=5 is given below for your reference:

You-can-move-one-step-at-a-time-in-any-one-of-the-four-directions

You can move one step at a time in any one of the four directions: “North”, “East”, “West”, “South”. At every cell of the grid, all four moves are possible. The only catch is that if you make a move that will take you out of the grid at a border cell, you will stay put at the same cell. Concretely, if you are at the cell (1,4) and try to move west, you will remain at the same cell. Or if you are at (3,1) and try to move south, you will remain there.

Write a function named final that accepts a positive integer n and a sequence of moves (string) as arguments and returns the final position where you would end up in an n×n grid-world if you start at (1,1). You must return a tuple of size 2, where the first element is the x-coordinate and the second is the y-coordinate.

You do not have to accept input from the user or print output to the console. You just have to write the function definition.

				
					    def final(n, moves):
        """
        Compute the final position
        
        Argument:
            n: int
            moves: string
        Return:
            (x, y): tuple
        """
        pos_x, pos_y = 1, 1
    
        for direction in moves:
            if direction == 'N' and pos_y < n:
                pos_y += 1
            elif direction == 'E' and pos_x < n:
                pos_x += 1
            elif direction == 'S' and pos_y > 1:
                pos_y -= 1
            elif direction == 'W' and pos_x > 1:
                pos_x -= 1
         return (pos_x, pos_y)