The Joy of Computing Using Python NPTEL Assignment 2 Answers 2026

Are you looking for The Joy of Computing Using Python NPTEL week 2 Answers 2026? You’ve come to the right place! Access the latest and most accurate solutions for your Assignment 2 in The Joy of Computing Using Python course


The Joy of Computing Using Python NPTEL week 2 Answers
These are The Joy of Computing Using Python NPTEL week 2 Answers 2026

The Joy of Computing Using Python Week 2 Nptel Answers(Jan-Apr 2026)

Que.1
How many times does the outer loop execute?

a) 4
b) 5
c) 6
d) Depends on the inner loop

View Answer


Que.2
Why does Ravi’s code print each number on a new line instead of the same line?

a) Because print() moves the cursor to the next line by default
b) Because range() creates new lines
c) Because the inner loop executes first
d) Because nested loops cannot print patterns

View Answer


Que.3
Ravi’s program executes without errors but fails to produce the required pattern. Which of the following best explains the cause?

a) The outer loop does not include the final value required for printing the last line
b) The inner loop variable is declared but not explicitly used in the print statement
c) The print statement is placed inside the inner loop instead of after it
d) The inner loop executes one fewer iteration than required for each value of i

View Answer


Que.4
After correcting the inner loop to execute the required number of times, Ravi observes that the digits are still printed on separate lines. Which change is necessary to ensure that each digit appears on the same line before moving to the next line?

a) Replace print(i) with print() inside the inner loop
b) Move the print(i) statement outside the inner loop
c) Add an empty print() statement at the beginning of the outer loop
d) Modify the print statement to suppress the default newline character

View Answer


Que.5
In the corrected nested-loop program, why is an additional print() statement required immediately after the inner loop completes?

a) To move the cursor to the next line after printing all digits for the current value of i
b) To reset the value of the loop variable before the next iteration begins
c) To ensure the inner loop terminates before the outer loop continues
d) To prevent the digits printed in different iterations from overlapping

View Answer


Que.6
Which of the following Python code snippets correctly produces the required output?

1
22
333
4444
55555

a) Option a
b) Option b
c) Option c
d) Option d

View Answer


Que.7
What is the final value of reverse when the function is called as is_palindrome(210)?

a) 210
b) 120
c) 21
d) 12

View Answer


Que.8
What will the function return for the input is_palindrome(210)?

a) Error because loop runs only once
b) True
c) False
d) None

View Answer


Que.9
How many times does the while loop execute when the function is called as is_palindrome(121)?

a) 2
b) 4
c) 3
d) 1

View Answer


Que.10
Suppose the loop condition is changed. What will happen when the function is called with is_palindrome(5)?

a) It enters an infinite loop
b) It returns False after one iteration
c) It correctly returns True
d) It raises a runtime error

View Answer


Que.11
A customer is a regular customer and makes a purchase of ₹850. Which code fragment correctly represents the discount logic applied by the calculator?

a) Option a
b) Option b
c) Option c
d) Option d

View Answer


Que.12
A premium customer makes a purchase of ₹1,500. Which discount will the system finally apply?

a) 5% premium discount
b) No discount
c) 10% purchase-based discount
d) Both 10% and 5% discounts

View Answer


Que.13
A premium customer makes a purchase of ₹2,500. Which logic ensures that only one discount is applied?

a) Option a
b) Option b
c) Option c
d) Option d

View Answer


Que.14
A premium customer makes a purchase of ₹2,000 exactly. Which discount amount is applied?

a) ₹100
b) ₹200
c) ₹300
d) ₹0

View Answer


Que.15
A premium customer makes a purchase of ₹1,800. Which of the following code fragments correctly produces the discount applied by the Smart Discount Calculator?

a) Option a
b) Option b
c) Option c
d) Option d

View Answer


(July-Dec 2025)


Question 1. What is the most appropriate data type to take customer input, calculate final price, and print the savings?
a) int
b) float
c) bool
d) str

View Answers


Question 2. What is the correct Python syntax to take customer purchase amount as input?
a) input(float())
b) float(input())
c) input = float()
d) float = input()

View Answers


Question 3. Which of the following correctly applies a 20% discount on the purchase amount stored in a variable amount?
a) discounted = amount * 0.2
b) discounted = amount – (amount * 0.2)
c) discounted = amount / 20
d) amount = amount * 0.8

View Answers

These are The Joy of Computing Using Python NPTEL week 2 Answers


Question 4. If a customer spends more than ₹5000, they get a 20% discount. Which of the following is the correct if statement to check this?
a) if amount > 5000:
b) if amount >= 5000:
c) if amount = 5000:
d) if amount => 5000:

View Answers


Question 5. What will be the output of the following code if the amount entered is 6000?
a) 6000
b) 4800
c) 5000
d) 1200

View Answers


Question 6. Ria wants to show the customer how much they saved. Which line of code correctly prints both the original price and the savings using f-strings?
a) print(“Original: ₹”, amount, “Saved: ₹”, saved)
b) print(f”Original: ₹{amount}, Saved: ₹{saved}”)
c) print(f’Original = ₹amount, Saved = ₹saved’)
d) print(“Original ₹f{amount}, Saved ₹f{saved}”)

View Answers


Question 7. Identify the error in the following code:
a) Missing else block
b) input cannot be used with float
c) Colon is missing after if condition
d) float should be int

View Answers


Question 8. What is the final price after applying the following logic?
a) 4000
b) 3600
c) 3200
d) 3500

View Answers

These are The Joy of Computing Using Python NPTEL week 2 Answers


Question 9. Which of the following best implements nested if logic to apply 20% discount if amount > 5000 and is a loyalty customer? Assume: is_loyal = True

View Answers


Question 10. What will be the output of the following program if the user inputs 4500?
a) Final Price: 4050.0
b) Final Price: 4499.9
c) Final Price: 4500.0
d) Final Price: 4499.9

View Answers


Question 11. Which Python loop is most suitable to print the multiplication table of a number from 1 to 10?
a) while loop
b) for loop
c) if loop
d) do-while loop

View Answers


Question 12. Ravi writes the following code to print the multiplication table of 5. What will be the output of the first line?
a) 5 x 0 = 0
b) 5 x 1 = 5
c) 1 x 5 = 5
d) 5 x 11 = 55

View Answers

These are The Joy of Computing Using Python NPTEL week 2 Answers


Question 13. What will be the output of range(1, 11) inside a for loop?
a) 1 to 10 (inclusive)
b) 0 to 10 (inclusive)
c) 1 to 11 (inclusive)
d) 1 to 9 (inclusive)

View Answers


Question 14. Which of the following loops will correctly continue asking the user for a number until they enter 0?

View Answers

These are The Joy of Computing Using Python NPTEL week 2 Answers


Question 15. What is the total number of lines printed by the following code?
a) 7
b) 10
c) 11
d) 0

View Answers


Question 16

Ravi wants to track how many tables were generated before the student exited. Which of the following variables and logic should be used?
a) Use count = 0, increment count by 1 inside the loop each time a table is printed
b) Use count = 1, decrement each time
c) Use count = 10, multiply inside the loop
d) No counter is needed

View Answers


Question 17. What will be the output of the following code?
a) Prints multiples of 3 up to 15
b) Prints an error
c) Infinite loop
d) Prints nothing

View Answers


Question 18. For input num = 5, i = 1, what will be printed?
a) 5 x 1 = 5
b) 1 x 5 = 5
c) x 5 = 5
d) i x num = result

View Answers

These are The Joy of Computing Using Python NPTEL week 2 Answers


Question 19. Which keyword is used to skip the current iteration of a loop and continue with the next one?
a) stop
b) break
c) continue
d) pass

View Answers


Question 20. What will this code output if the user enters the following numbers sequentially in the terminal: 3, 4, 5, 0?
a) 3 tables printed, followed by: “You practiced 3 tables.”
b) Infinite loop
c) Error due to missing condition
d) 4 tables printed

View Answers


Question 21. What is the role of the first while loop in the program?
a) It checks whether the number is divisible by 10
b) It calculates the cube of digits
c) It finds how many digits are in the number
d) It stores the reverse of the number

View Answers

These are The Joy of Computing Using Python NPTEL week 2 Answers


Question 22. What will be the output when the input is 9474?
a) Armstrong Number
b) Not an Armstrong Number
c) Error due to integer overflow
d) Infinite loop

View Answers


Question 23. How many times does the body of each while loop execute when the input is 1000?
a) 3
b) 4
c) 5
d) It never executes

View Answers


Question 24. What is the value of sum immediately after the second while loop finishes when the input is 370?
a) 0
b) 370
c) 3700
d) 27

View Answers


Question 25. If the line temp = num that appears just before the second loop is deleted, what will the program output for input 9474?
a) Armstrong Number
b) Not an Armstrong Number
c) The program hangs
d) Raises NameError

View Answers

These are The Joy of Computing Using Python NPTEL week 2 Answers


Question 26. During execution with input 1000, what is the value of digit in the third iteration of the second while loop?
a) 0
b) 1
c) 10
d) The loop has no third iteration

View Answers


Question 27. Which replacement for the line if sum == original: will make the program print “Armstrong Number” for every positive input but “Not an Armstrong Number” for zero?
a) if sum >= original:
b) if original != 0:
c) if original > 0:
d) if True:

View Answers


Question 28. What final value does count take when the input is 1634?
a) 3
b) 4
c) 5
d) 6

View Answers


Question 29. Which single-line change will guarantee that no input at all (including 0) is reported as an Armstrong number?
a) Initialize sum to 1 instead of 0
b) Initialize count to 1 instead of 0
c) Replace digit = temp % 10 with digit = abs(temp % 10)
d) Change the condition to if sum >= original:

View Answers

These are The Joy of Computing Using Python NPTEL week 2 Answers


Question 30. What does the program print when the user enters -153?
a) Armstrong Number
b) Not an Armstrong Number
c) Infinite loop
d) Raises ValueError

View Answers


(Jan-Apr 2025)

Course Link: Click Here


  1. 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.

View Answer


  1. Which of the following code blocks prints – “Ramesh talks to Suresh and Kamlesh”?
    a. print(j'Ramesh talks to Suresh and Kamlesh" + and")
    b. print("Ramesh talks to " "Suresh" " Kamlesh")
    c. print("Ramesh talks to Suresh" " and " " Kamlesh ")
    d. print("Ramesh talks to" "Suresh and Kamlesh")

View Answer


  1. 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)

View Answer


  1. The following program outputs 723.
def mystery(container):
    result = []
    for i in range(len(container)):
        result.append(i)
    else:
        result.append(len(container))
    return result

For what value of a does the code output 123?
a. 1
b. 2
c. 6
d. 5

View Answer

These are The Joy of Computing Using Python NPTEL week 2 Answers


  1. What does the 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 a multiples of a starting from 1 and adds 3.

View Answer


  1. 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

View Answer


  1. 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 with the program from the lines after the if/while block.
    c. Python interpreter executes the if/while blocks and the rest of the program.
    d. Python interpreter executes the if/while blocks, and the program runs in an infinite loop.

View Answer

These are The Joy of Computing Using Python NPTEL week 2 Answers


  1. The following program might/might not have an infinite loop. Does the program have an infinite loop?
while True:
    a.append(n % 10)
    a.sort()
    for i in a:
        if (b < k):
            print("FUN")
        else:
            print("IS BORING")

a. No, the program doesn’t have an 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.

View Answer


  1. For which of the following values of name and age variables does the following code print ‘You are lucky’?
name = input("Enter your name: ")
age = int(input("Enter your age: "))
flag = False
if age > 18:
    flag = True
counter = 0
for i in name:
    counter += 1
if flag and (counter % 2 == 0):
    print("You are lucky")
else:
    print("You are not lucky")

a. aryan, 20
b. arjun, 19
c. aakash, 16
d. anand, 18

View Answer


  1. For which of the options from the previous question does the program not print anything?
    a. aryan, 20
    b. aakash, 16
    c. arjun, 19
    d. anand, 18

View Answer


Session: JULY- DEC 2024


Q1.Statement : If a variable is assigned multiple times, the latest value is not stored in the variable
False, the variable stores all values it was assigned
False, the variable stores the value from the latest assignment.
True, the variable stores the value from the second-last assignment.
True, the variable stores value from the initial assignment

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



Q2. Which of the following code blocks print – ”Hello Ram Lakshman and Hanuman !” ?

Answer: a),c)



For answers or latest updates join our telegram channel: Click here to join

These are The Joy of Computing Using Python NPTEL week 2 Answers


Q3. What aren’t the correct ways to inform python that input is an integer ?
in(input())
float(input())
int(input())
a = input()
a = int(a)

Answer: in(input())
float(input())



Q4. The following program outputs 722 –
For what value of a does the code output 8 ?
2
1
4
6

Answer: 4



For answers or latest updates join our telegram channel: Click here to join

These are The Joy of Computing Using Python NPTEL week 2 Answers


Q5. What does previous question calculate ?
Calculates the factorial of a.
Calculates the factorial of a and adds 2.
Calculates the a multiples of a starting from 1 and adds 2.
Calculates the factorial of a-1 and adds 2.

Answer: Calculates the factorial of a-1 and adds 2.



Q6. Which loop is used to perform a set of repetitive tasks based on condition in Python?
while loop
for loop
do-while loop
while-range loop

Answer: while loop


For answers or latest updates join our telegram channel: Click here to join

These are The Joy of Computing Using Python NPTEL week 2 Answers


Q7. What happens when the condition inside the if and while evaluate to false ?
Python interpreter ignores the if/while blocks, and halts the program.
Python interpreter ignores the if/while blocks, and proceeds the program from the lines after the if/while block.
Python interpreter executes the if/while blocks, and rest of the program.
Python interpreter executes the if/while, and the programs runs in an infinite loop.

Answer: 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 ?

No, the program doesn’t have infinite loop.
Yes, it can be prevented by updating the value of a before the if block at line 3
Yes, it can be prevented by removing both the if blocks inside the while loop.
Yes, but it cannot be prevented

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


For answers or latest updates join our telegram channel: Click here to join

These are The Joy of Computing Using Python NPTEL week 2 Answers


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

aryan, 20
arjun, 19
aakash, 17
aatreya, 18

Answer: aatreya, 18


Q10. For which of the options among the previous question, the program doesn’t print anything.
aryan, 20
arjun, 19
aakash, 17
aatreya, 18

Answer: aakash, 17


For answers or latest updates join our telegram channel: Click here to join

These are The Joy of Computing Using Python NPTEL week 2 Answers

All Weeks of The Joy of Computing Using Python: Click here

For answers to additional Nptel courses, please refer to this link: NPTEL Assignment Answers