NPTEL Joy Of Computing Using Python Week 2 Assignment Answer

ABOUT THE 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.

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.

NPTEL Joy Of Computing Using Python Week 2 Assignment Answer

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 !!

NPTEL Joy Of Computing Using Python Week 2 Assignment Answer

Q1. Statement: If a variable is assigned a value once, the value in the variable cannot be changed in the variable.

A. False, the variable stores all values it was assigned.

B. False, the variable stores the value from the latest assignment.

C. True, the variable stores only the value from the second-last assignment.

D. True, the variable stores value from the initial assignment only.

Answer: [ B ] False, the variable stores the value from the latest assignment.

 

 

 

Q2. Which of the following code blocks print – ”Ramesh talks to Suresh and Kamlesh” ?

A. print (“Ramesh talks to Suresh and Kamlesh”)

B. print (“Ramesh talks to” + “Suresh” + ”  and”,  “Kamlesh”)

C. print (“Ramesh talks to Suresh”, “and”, ” Kamlesh”)

D. print (“Ramesh talks to” + ” Suresh and Kamlesh”)

Answer: [ A, B, C ] 

The Output is

 

Which of the following code blocks print - ”Ramesh talks to Suresh and Kamlesh”

 

 

 

Q3. What aren’t the correct ways to inform python that input is a decimal point number ?

A. in(input())

B. float(input())

C.  int(input())

D. a = input()

a = int(a)

Answer: [ A, C, D ]

Q4. The following program outputs 723 –

def mystery(container):
       res=[ ]
       for i in range(len(container)):
             if i%2 !=0:
                 result.appppend(container[i]*4)
             else:
                 result.append(container[i]*(-1))

return result

For what value of a does the code output 123 ?

A. 1

B. 2

C. 6

D. 5

Answer: [ C ] 6

Q5. What does previous question calculate ?

A. Calculates the factorial of a.

B. Calculates the factorial of a-1 and adds 3

C. Calculates the factorial of a-1+3.

D. Calculates the a multiples of a starting from 1 and adds 3.

Answer: [ C ] Calculates the factorial of a-1+3

Q6. Which loop is used to perform a set of repetitive tasks without a condition by default in Python?

A. while loop

B. for loop

C. do-while loop

D. while-range loop

Answer: [ B ] for loop

Q7. What happens when the condition inside the if and while evaluate to false ?

A. Python interpreter ignores the if/while blocks, and halts the program.

B. Python interpreter ignores the if/while blocks, and proceeds the program from the lines after the  if/while block.

C. Python interpreter executes the if/while blocks, and rest of the program.

D. Python interpreter executes the if/while, and the programs runs in an infinite loop.

Answer: [ B ] Python interpreter ignores the if/while blocks, and proceeds the program from the lines after the  if/while block.

 

 

Q8. The following program might/might not have an infinite loop. Does the program have infinite     loop ?

A. No, the program doesn’t have infinite loop.

B. Yes, it can be prevented by updating the value of a before the if block at line 3.

C. Yes, it can be prevented by removing both the if blocks inside the while loop.

D. Yes, but it cannot be prevented.

Answer: [ D ] 

Q9. For which of the following values of name and age variables does the following code print ”You are lucky”?

A. aryan, 20

B. arjun, 19

C. aakash, 16

D. anand, 18

Answer: [ A ] [ D ]

Q10. For which of the options among the previous question, the program doesn’t print anything.

A. aryan, 20

B. aakash, 16

C. arjun, 19

D. anand, 18

Answer: [ B ] aakash, 16

Week 2: Programming Assignment 1

Due on 2025-02-06, 23:59 IST

Create a Python program that calculates the sum of the squares of the first n natural numbers. The program should prompt the user to input a number n, then compute and print the sum of squares from 1 to n.

Input Format: The input consists of a single integer, n.

Output Format: The output consists of the sum of squares of the first n natural numbers.

Example:
Input:
5

Output:
55

 

Week 2: Programming Assignment 2

Due on 2025-02-06, 23:59 IST

Write a Python program to calculate the arithmetic mean of n numbers, rounding the result to the nearest integer. The program should first take a single line of input containing n space-separated integer numbers, and then output the rounded mean of these numbers.

Input Format:
The input consists of a single line containing an integer n followed by n space-separated numbers.

Output Format:
The output is the arithmetic mean of the input numbers, rounded to the nearest integer.

Example:
Input:
5 10 15 20

Output:
13

Week 2: Programming Assignment 3

Due on 2025-02-06, 23:59 IST

Develop a Python program that determines the mode of a list of n numbers, assume only one mode exists in the provided test cases. The program should ask for a single line of input containing n, then n space-separated numbers, and output the mode.

Input Format:
The first line contains an integer n, followed by n space-separated numbers.

Output Format:
The output is the mode of the list.

Example:
Input:
5 1 2 2 3 4

Output:
2

Related Posts