NPTEL The Joy of Computing Using Python Week2 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 Week2 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 : Accept two positive integers M and N as input. There are two cases to consider:

                      (1) If M < N, then print M as output.
                      (2) If M >= N, subtract N from M. Call the difference M1.
If M1 >= N, then subtract N from M1 and call the difference M2. Keep doing this operation until you reach a value k, such that, Mk < N. You have to print the value of Mk as output.
					M = int(input())
N = int(input())

# Case 1: If M < N, then print M as output
if M>0 and N>0:
  if M < N:
      # Case 2: If M >= N, subtract N from M until Mk < N
      while M >= N:
          M -= N
      # Print the value of Mk as output

Programming Assignment 2

Question 2 : Accept three positive integers as input and check if they form the sides of a right triangle. Print YES if they form one, and NO if they do not. The input will have three lines, with one integer on each line. The output should be a single line containing one of these two strings: YES or NO.

					# Accept three positive integers as input
a = int(input())
b = int(input())
c = int(input())

# Check if they form the sides of a right triangle using the Pythagorean theorem
if a**2 + b**2 == c**2 or b**2 + c**2 == a**2 or c**2 + a**2 == b**2:
    print("YES", end="")
    print("NO", end="")

Programming Assignment 3

Question 3Accept a string as input. Your task is to determine if the input string is a valid password or not. For a string to be a valid password, it must satisfy all the conditions given below:

(1) It should have at least 8 and at most 32 characters
(2) It should start with an uppercase or lowercase letter
(3) It should not have any of these characters: / \ = ‘ “
(4) It should not have spaces
It could have any character that is not mentioned in the list of characters to be avoided (points 3 and 4). Output True if the string forms a valid password and False otherwise.
					# Accept a string as input
password = input()

# Check if the string is a valid password
def is_valid_password(password):
    # Condition 1: Check the length
    if 8 <= len(password) <= 32:
        # Condition 2: Check the first character is an uppercase or lowercase letter
        if password[0].isalpha():
            # Condition 3: Check for forbidden characters
            forbidden_chars = {'/', '\\', '=', "'", '"'}
            if not any(char in forbidden_chars for char in password):
                # Condition 4: Check for spaces
                if ' ' not in password:
                    return True

    return False

# Output True if the string forms a valid password, and False otherwise
print(is_valid_password(password), end="")

Leave a Reply

Your email address will not be published. Required fields are marked *