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

Need help with this week’s assignment? Get detailed and trusted solutions for The Joy of Computing using Python Week 7 NPTEL Assignment Answers. Our expert-curated answers help you solve your assignments faster while deepening your conceptual clarity.

✅ Subject: The Joy of Computing using Python
📅 Week: 7
🎯 Session: NPTEL 2025 July-October
🔗 Course Link: Click Here
🔍 Reliability: Verified and expert-reviewed answers
📌 Trusted By: 5000+ Students

For complete and in-depth solutions to all weekly assignments, check out 👉 NPTEL The Joy of Computing using Python Week 7 NPTEL Assignment Answers

🚀 Stay ahead in your NPTEL journey with fresh, updated solutions every week!

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

1. In the function play(), what is the significance of the variable turn?

  • It tracks the number of dice rolls
  • It ensures alternating turns between the two players
  • It ends the game after a fixed number of turns
  • It stores the winning score
Answer : See Answers

2. What happens in the code when a player rolls a number that moves them past position 100?

  • The game ends and they win
  • The player’s position resets to 0
  • The player stays in the same position (doesn’t move)
  • The player is forced to roll again
Answer :

3. What is the purpose of the following lines in the play() function?

  • To restart the game
  • To display final scores and exit if the player chooses not to continue
  • To check if the player reached a snake
  • To decide the winner
Answer :

4. If Ankan is at position 47 and the snakes dictionary contains 47:26, what will happen immediately after his dice roll moves him to 47?

  • He will stay at 47
  • He will move to 100
  • He will go to 26
  • The game will end
Answer :

5. What does the function show_board() attempt to do?

  • Display current scores
  • Roll the dice for both players
  • Open and display the game board image
  • Initialize the snake and ladder dictionaries
Answer :

6. Which of these functions is called after a player moves and before their position is printed?

  • show_board()
  • play()
  • check_ladder() and check_snake()
  • reached_end() only
Answer : See Answers

7. How many times is the line random.randint(1, 6) evaluated in one full round of both players’ turns?

  • Once
  • Twice
  • Four times
  • Depends on the player positions
Answer :

8. Which part of the code ensures that the game stops immediately when a player reaches exactly 100?

  • if pp1 > end:
  • if pp1 == 100:
  • if reached_end(pp1):
  • if check_ladder(pp1):
Answer :

9. Consider the following ladders dictionary (in the format bottom: top): ladders = {1: 38, 4: 14, 9: 31, 21: 42, 28: 84, 36: 44, 51: 67, 71: 91, 80: 100}

If a player is on 27, rolls a 1, and lands on 28, what will happen next?

  • The player will stay on 28 because it’s not a ladder base
  • The player climbs the ladder to 84
  • The player must roll again because 28 is a special position
  • The code throws an error because 28 is not handled explicitly
Answer :

10.

Why is the condition turn % 2 == 0 used in this part of the code?

  • To check if the game has reached the second round
  • To make sure player 2 only plays after player 1 wins
  • To alternate turns between the two players using the value of turn
  • To skip the dice roll for even-numbered turns
Answer : See Answers

11. What will be the output of the following code?

  • “map”
  • “torch”
  • “compass”
  • IndexError
Answer :

12. What will happen when Dilrez runs this code?

  • Prints (“magic map”, “compass”, “torch”)
  • Gives a TypeError
  • Prints original backpack
  • Gives a SyntaxError
Answer :

13. What will be the output?

Select all that apply:

  • The output will contain only unique elements
  • The output may appear in any order
  • It will raise a syntax error due to duplicate elements
  • The output will be a list with 2 elements
Answer :

14. What will be the final contents of the pouch?

  • {‘potion’, ‘gem’}
  • {‘gem’}
  • [‘gem’]
  • Error due to remove()
Answer :

15. What is the type of x in the following code?

  • < class ‘tuple’ >
  • < class ‘list’ >
  • < class ‘str’ >
  • < class ‘set’ >
Answer :

16. Which of the following statements is true?

  • Tuples can’t store duplicate items
  • Sets maintain the order of elements
  • Sets automatically remove duplicate items
  • Tuples can be changed after creation
Answer : See Answers

17. What will this code output?

  • 3 3
  • 2 2
  • 3 2
  • 2 3
Answer :

18. Dilrez tries to update a tuple. Find and fix the error:

What’s the issue?

  • Tuple index out of range
  • Syntax error in tuple
  • Tuples are immutable
  • Need to use append()
Answer :

19. What will be the output of the following code?

  • 4 2 (‘map’, ‘torch’)
  • 4 2 (‘torch’, ‘map’)
  • 2 2 (‘map’, ‘torch’)
  • 4 4 (‘map’, ‘torch’, ‘torch’, ‘map’)
Answer :

20. Dilrez does the following:

Which of the following is true based on this setup?

  • All three containers contain the same items and in the same order
  • Only the pouch automatically removes duplicates
  • backpack[1] and supply_list[1] give the same result
  • Sets can be indexed just like lists and tuples
Answer : See Answers

21. Why does the code return 1 when n == 0?

  • Because 0 × anything is 0
  • To stop the recursion at some point
  • By mistake; it should return 0
  • It helps to calculate square of the number
Answer :

22. What will be the return value of factorial(1)?

  • 0
  • 1
  • It will call itself infinitely
  • 2
Answer :

23. Identify the error in the following code:

  • It will return 6
  • No base case defined, will result in infinite recursion
  • n is not decremented
  • Syntax error
Answer :

24. What does the line n! = n × (n-1) × (n-2) × … × 1 represent in the comprehension?

  • An infinite series
  • A summation of natural numbers
  • A recursive definition of factorial
  • A non-recursive mathematical shortcut
Answer :

25.

How many recursive calls are made when he executes factorial(4)?

  • 3
  • 4
  • 5
  • Infinite
Answer :

26. Himmat accidentally writes:

What will happen if he calls factorial(0)?

  • Returns 1
  • Returns 0
  • Throws a recursion error
  • Returns -1
Answer :

27. What would be a correct way to make Himmat’s function handle negative numbers safely?

  • Add return -1 for all inputs
  • Add a base case if n < 0: return “Invalid input”
  • Remove recursion altogether
  • Multiply by -1 inside the function
Answer :

28. If Himmat’s function is modified as:

What happens when factorial(3) is called?

  • Returns 6
  • Returns 0
  • Infinite recursion
  • Error due to syntax
Answer :

29. Himmat runs this code to reverse a string:

What will be the output?

  • “a”
  • “”
  • Error (index out of range)
  • “aa”
Answer :

30. Himmat wants to reverse the word “race” using recursion. He writes a function that checks whether the string is non-empty as the base case.

What will be the output of reverse_string(“race”)?

  • “race”
  • “ecar”
  • “rcae”
  • Error due to slicing empty string
Answer : See Answers

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

1. The Chaupar game, also known as Pachisi, involves a player moving their pieces around a cross-shaped board based on the throw of dice (or cowrie shells). The objective is to reach the centre of the board. The steps required to implement the game are given below

Answer :- 213
Explanation: The correct sequence of implementation steps is 2 → 1 → 3 for proper game logic and flow.


2. Given below is a simple algorithm for a Snake and Ladder game. Identify the correct statements regarding variations in the algorithm.

a. A and B
b. Only B
c. A and C
d. Only C

Answer :- c
Explanation: Changing to an octahedral dice (8-faced) affects Step II, and increasing the board to 200 tiles affects both Step I (board setup) and Step III (winning condition).


3. Nishan generates the function is_prime(position) to check if a player lands on a prime tile. Identify the error line, or -1 if there is no error.

Answer :- 2
Explanation: There’s likely a logical or syntactical error on line 2 in the function definition or prime-checking loop.


4. Find the error in the line of code written using the turtle library to draw a square. In the absence of an error, enter -1.

Answer :- 7
Explanation: Line 7 likely has a syntax or logic error preventing the square from being drawn properly.


5. Identify the correct statements regarding printing a matrix in a snake pattern. [MSQ]

a. When parity is 0, we print the elements of the row from left to right
b. When parity is 1, we print the elements of the row from left to right
c. When parity is 0, we print the elements of the row from right to left
d. When parity is 1, we print the elements of the row from right to left

Answer :- a, d
Explanation: Even-indexed rows (parity 0) go left to right, odd-indexed rows (parity 1) go right to left for snake pattern.


6. Which of these conditions guarantee that the element is a boundary element of a matrix of order m × n? [MSQ]

a. i == 0
b. i == m-1
c. j == 0
d. j == n-1

Answer :- a, b, c, d
Explanation: Any element in the first or last row/column is a boundary element.


7. Given a set of 4 integers as input, the following code tries to print them in a 2×2 matrix. Identify the error line, or -1 if there’s no error.

Answer :- -1
Explanation: The code correctly converts the 4 integers into a 2×2 matrix, hence no error.


8. How can you write data to a CSV file using the csv module?

a. write_csv_file()
b. csv.writer()
c. csv.write()
d. write_csv()

Answer :- b
Explanation: csv.writer() is used to write to a CSV file in Python.


9. Which object is commonly used for reading rows from a CSV file in Python?

a. csv.parser
b. csv.handler
c. csv.reader
d. csv.iterator

Answer :- c
Explanation: csv.reader reads each row from a CSV file as a list.


10. Identify the correct statement(s) regarding the gmplot library.

a. I only
b. II only
c. Both I and II
d. Neither I nor II

Answer :- c
Explanation: gmplot is used to plot data on Google Maps, and gmplot.GoogleMapPlotter(lat, lon, zoom) is the correct constructor.