Hey Folks, This article is about the Joy of Computing Using Python week 5 assignment answers. Come with us until the last to know more about the answers.Â
Also Read: Joy of Computing using Python Week 4 Programming Answers
NPTEL Joy Of Computing Using Python Week 5 Answers 2024
Last Date: 28-02-2024
Q1. Imagine the Monty Hall problem had four doors instead of three, and Monty opened one door to reveal a goat after your initial choice, what would be the probability of winning the car by switching?
A. 1/2
B. 1/3
C. 1/4
D. 3/4
Answer: [ D ] 3/4Â
Q2. What happens if you try to add a new key-value pair to a dictionary using a key that already exists in the dictionary?
A. The new value overwrites the existing value
B. An error is raised
C. The dictionary becomes immutable
D. The new value is appended to the existing value
Answer: [ A ] The new value overwrites the existing value
- Rock wins against Scissors.
- Scissors wins against Paper.
- Paper wins against Rock.
- Rock wins against Lizard.
- Lizard wins against Spock.
- Spock wins against Scissors.
- Scissors wins against Lizard
- Lizard wins against Paper
- Paper wins against Spock.
- Spock wins against Rock.
Each option can defeat two other options, lose to two other options, and draw with one other option.
Now, the major steps involved in the algorithm for coding a rock-paper-scissors game as discussed in the lecture include:
1) Assigning values to the choices: The algorithm involves assigning numerical values to the rock, paper, and scissors choices, such as 1 for rock, 2 for paper, and 3 for scissors.
2) Inputting user choices: The algorithm prompts the users to input their choices for the game, such as rock, paper, or scissors.
3) Secret bit positions: The algorithm uses secret bit positions to determine the winner of the game, which involves bitwise operations to compare the choices and determine the outcome.
4) Coding the rules: The algorithm includes coding the rules for determining the winner based on the choices made by the players, such as using if-else conditions to compare the choices and declare the winner.
5) Running the program: The algorithm allows for running the program to test the rock- paper-scissors game with different user inputs and provides examples of the game outcomes.
What would be the possible change in steps for running “Rock, Paper, Scissors, Lizard, Spock"?
A. Step 1 would involve assigning 5 values to choices instead of 3
B. The bitwise operations involved in Step 3 would involve modulo operation with 5 instead of 3
C. None of the above
D. All the above
Answer: [ D ] All the aboveÂ
Q4. How does Bubble Sort compare elements in an array?
A. Compares adjacent elements and swaps if they are in the wrong order
B. Compares random elements in the array
C. Compares all elements with the first element
D. Compares elements in reverse order
Answer: [ A ] Compares adjacent elements and swaps if they are in the wrong order
Q5. To sort a list in ascending order when does Bubble Sort exhibit poor performance?
A. When the list is sorted in ascending order
B. When the list is sorted in descending order
C. When the list contains unique elements
D. Bubble Sort always exhibits poor performance
Answer: [ B ] When the list is sorted in descending order
Q6. How many passes does Bubble Sort make through the array in the worst-case scenario for sorting n elements?
A. n
B. n-1
C. 2n
D. n2
Answer: [ B ]Â
Q7. How many pairs of adjacent elements are compared in a single pass of the bubble sort algorithm?
 A. n
 B. n-1
 C. n/2
 D. 2n
Answer: [ B ]
Q9. The following steps are required to implement the binary search for an array sorted in ascending order.1)
1)Initialize Pointers:
- Set two pointers, `low` and `high`, initially pointing to the start and end of the array, respectively.
2) Calculate Midpoint:
- Calculate the midpoint index using the formula `mid = (low + high) // 2`.
3) Compare Midpoint Element:
- Compare the element at the midpoint with the target element you are searching for:
- If the midpoint element is equal to the target, the search is successful, and you can return the index.
- If the midpoint element is less than the target, update `low` to `mid + 1` and continue the search in the right half.
- If the midpoint element is greater than the target, update `high` to `mid - 1` and continue the search in the left half.
4) Repeat:
- Repeat steps 3-4 until the `low` pointer is greater than the `high` pointer. This means the search range has become empty.
5) Return Result:
- If the target element is found, return its index. If the target is not found, return a sentinel value (e.g.,-1) to indicate that the element is not in the array.
Which steps would require modification if the array were sorted in descending order?
 Step 2
 Step 4
 Steps 2 and 4
 No modification in steps
Answer: [ B ] Step 4
Q9. Select the correct statements among the following
A. In the presence of duplicate elements in a list, binary search always finds the first occurrence of the element in the list
B. In the presence of duplicate elements in a list, binary search may or may not find the first occurrence of the element in the list
C. In the presence of duplicate elements in a list, the existing binary search algorithm with minor modifications can be used to find the first occurrence of the target element in the list
D. In the presence of duplicate elements in a list , the existing binary search can be used to find any kth(k can be any number from 1 to number of times the element has been repeated) of target element in the list
Answer: [ B ] [ C ]Â
Q10. Swapping of two numbers is an intermediate step in any sorting algorithm, In the lecture we use a temporary variable to swap two elements in the list.
Can swapping of two numbers be done without using a temporary variable?
 A. Yes
 B. No
 C. Depends on size of list
 D. Depends on nature of elements in the list
Answer: [ A ]Â
Also Read:Â Joy of Computing using Python Week 4 Programming Answers
Conclusion
Join the telegram channel for any future updates.Â