NPTEL The Joy of Computing Using Python Week3 Assignment 2024

NPTEL-The-Joy-of-Computing-Using-Python-Week3-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 Week3 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 1You are given a list marks that has the marks scored by a class of students in a Mathematics test. Find the median marks and store it in a float variable named median. You can assume that marks is a list of float values.

Procedure to find the median

(1) Sort the marks in ascending order. Do not try to use built-in methods.

(2) If the number of students is odd, then the median is the middle value in the sorted sequence. If the number of students is even, then the median is the arithmetic mean of the two middle values in the sorted sequence.

You do not have to accept input from the console as it has already been provided to you. You do not have to print the output to the console. Input-Output is the responsibility of the auto-grader for this problem.

				
					    n = len(marks)
    for i in range(n - 1):
        for j in range(0, n - i - 1):
            if marks[j] > marks[j + 1]:
                marks[j], marks[j + 1] = marks[j + 1], marks[j]

    # Calculate the median
    if n % 2 == 1:
        # If the number of students is odd, then the median is the middle value
        median = marks[n // 2]
    else:
        # If the number of students is even, then the median is the mean of the two middle values
        middle1 = marks[(n - 1) // 2]
        middle2 = marks[n // 2]
        median = (middle1 + middle2) / 2
				
			

Programming Assignment 2

Question 2 : Accept a string as input, convert it to lower case, sort the string in alphabetical order, and print the sorted string to the console. You can assume that the string will only contain letters.

				
					input_string = input()

# Convert the string to lowercase
lowercase_string = input_string.lower()

# Sort the string in alphabetical order
sorted_string = ''.join(sorted(lowercase_string))

# Print the sorted string to the console
print(sorted_string,end="")
				
			

Programming Assignment 3

Question 3 : You are given the dates of birth of two persons, not necessarily from the same family. Your task is to find the younger of the two. If both of them share the same date of birth, then the younger of the two is assumed to be that person whose name comes first in alphabetical order (names will follow Python’s capitalize case format).

 
The input will have four lines. The first two lines correspond to the first person, while the last two lines correspond to the second person. For each person, the first line corresponds to the name and the second line corresponds to the date of birth in DD-MM-YYYY format. Your output should be the name of the younger of the two.
				
					from datetime import datetime

# Read the details of the first person
name1 = input()
dob1 = datetime.strptime(input(), "%d-%m-%Y")

# Read the details of the second person
name2 = input()
dob2 = datetime.strptime(input(), "%d-%m-%Y")

# Compare the dates of birth
if dob1 > dob2 or (dob1 == dob2 and name1 < name2):
    print(name1,end="")
else:
    print(name2,end="")