The Joy of Computing using Python Week 2 NPTEL Assignment Answers 2025

NPTEL The Joy of Computing using Python Week 2 Assignment Answers 2024

1. At any given point during a program’s execution, what value is held within a variable?

  • The value it was initially assigned when it was created.
  • The sum of all values that have ever been assigned to it.
  • The most recent value that was assigned to it.
  • The average of all values that have ever been assigned to it.

Answer: c
Explanation: A variable always holds the most recently assigned value during program execution, replacing any previous values.


2. What will be the output of the following Python code snippet?

Which of the following represents the correct output if the user inputs “25”?

  • The value is: 25
  • 25
  • The value is:
  • None of the above

Answer: a
Explanation: If the code includes a print statement like print("The value is:", value) and user inputs “25”, the output will be "The value is: 25".


3. What are the possible loop values that can be specified in the range argument of a for loop in Python, and why are these values used?

  • Integers, representing the starting and ending points of the loop, allowing iteration through a specified range of numbers.
  • Floating-point numbers, enabling iteration through decimal ranges with precise steps.
  • Strings, facilitating iteration through characters in a specified string
  • Tuples, allowing iteration through multiple sequences simultaneously.

Answer: a
Explanation: The range() function in Python works only with integers, which specify where to start and stop iteration.


4. What values can be used in the argument of a while loop in Python, and why are these values used?

  • Integers, representing the starting and ending points of the loop, allowing iteration through a specified range of numbers
  • Boolean expressions or conditions, enabling the loop to execute until the condition becomes False.
  • Floating-point numbers, allowing iteration through decimal ranges with precise steps.
  • Strings, facilitating iteration through characters in a specified string.

Answer: b
Explanation: A while loop in Python continues running as long as its Boolean condition evaluates to True.


5. What types of conditional entries can be used in a Python if statement, and why are these entries used?

  • Integers, representing specific numeric values to check against a variable, ensuring a match for equality
  • Boolean expressions or conditions, evaluating to True or False and determining the path of execution in the code.
  • Strings, enabling comparison of text values for exact matches in the condition
  • Floating-point numbers, allow range-based conditions to check if a variable falls within a specific numerical range.

Answer: b
Explanation: Python if statements depend on Boolean expressions to decide whether a block of code should be executed.


6. Consider the following code snippet:

What does the code do?

  • Takes an input n, computes the multiplication table of n from 1 to 10, and prints each multiplication.
  • Takes an input n, computes the multiplication table of n from 1 to 11, and prints the final product.
  • Takes an input n, computes the multiplication table of n from 1 to 10, and prints the final product.
  • Takes an input n, initializes i to 1, and prints the multiplication of n and i without any loop.

Answer: a
Explanation: A loop running from 1 to 10 will multiply n with each i and print the result, forming a multiplication table.


7. Consider the following code snippet:

What does the code do?

  • Takes an input number, computes the multiplication table of numbers from 1 to 10, and prints each multiplication
  • Takes an input number, computes the multiplication table of numbers from 1 to 11, and prints the final product.
  • Takes an input number, computes the multiplication table of numbers from 1 to 10, and prints the final product.
  • Takes an input number, initializes i to 1, and prints the multiplication of number and i without any loop.

Answer: a
Explanation: This loop prints each step of the multiplication table one by one from 1 to 10.


8. Consider the following code snippet:

What does the code do?

  • Takes an input num, computes the factorial of num, and prints the factorial value.
  • Takes an input num, computes the product of numbers from 1 to num, and prints the final product.
  • Takes an input num, computes the sum of numbers from 1 to num, and prints the final sum.
  • Takes an input num, initializes the result to 1, and prints the value of the result without any factorial computation.

Answer: a, b
Explanation: Computing factorial involves multiplying numbers from 1 to num, which matches both the first and second options.


9. An Integrated Development Environment (IDE) is a software application that provides comprehensive facilities to computer programmers for software development. Which of the following are IDEs?

  • PyCharm
  • Spyder
  • Visual Studio Code (VS Code)
  • C# (pronounced “C sharp”)

Answer: a, b, c
Explanation: PyCharm, Spyder, and VS Code are all IDEs. C# is a programming language, not an IDE.


10. A Python distribution is a software bundle, which contains a Python interpreter and the Python standard library. What is Anaconda being discussed in lectures?

  • A species of snake
  • A type of programming language
  • An integrated development environment (IDE)
  • A Python distribution for scientific computing and data science

Answer: d
Explanation: Anaconda is a Python distribution that includes tools like Jupyter, NumPy, Pandas, and is widely used in data science.