#### The Joy of Computing using Python Week 5 - Assignment 5 | NPTEL | Answer with Explanation

##### "Discover the Excitement of Computing with Python | Week 5 Multiple Choice Questions - Get ready to enhance your programming skills and deepen your understanding of the Python language with this week 5 MCQ on 'The Joy of Computing using Python'. Test your knowledge and boost your confidence as a Python programmer today!"

## The Joy of Computing using Python - Course | NPTEL - All assignment

## Binary search can be applied on ___.

a. Sorted listb. Unsorted list

c. Both A and B

d. Any list with any elements

## Answer

a. Sorted list

- Binary search is applied only on the sorted list it can not apply to an unsorted list.

- It is an efficient algorithm for searching for a specific element in a sorted list by repeatedly dividing the search interval in half until the element is found or determined to be not in the list.

- If the list is unsorted, binary search cannot be applied, as the algorithm relies on the fact that the list is already sorted to divide the search interval in half.

- For an unsorted list, a different search algorithm like linear search is typically used.

## Which of the following is a Waveform Audio File Format.

a. Wavb. Wave

c. Wv

d. Waves

## Answer

a. Wav,

b. Wave

WAV is a commonly used audio file format that stores audio data in a digital format. It is a lossless audio format that maintains high quality and is compatible with a wide range of software and hardware.

## Which of the following libraries can help us to convert audio into lyrics?

a. speech_recognitionb. text_to_speech

c. speech_to_text

d. text_translate

## Answer

a. speech_recognition

SpeechRecognition: A library that supports multiple speech recognition engines, including Google Speech Recognition, PocketSphinx, and Microsoft Bing Voice Recognition.

PyAudio: A library for working with audio streams, which can be used in conjunction with SpeechRecognition for live audio recognition.

DeepSpeech: An open-source speech-to-text engine developed by Mozilla.

## State True or False: In the monte hall problem, swapping the choice does not increase the chance of winning. (For the large number of experiments)

a. Swapping will decrease the chance of winning.b. Swapping will increase the chance of winning.

c. Swapping will not affect the chance of winning.

d. Swapping may or may not increase the chance of winning.

## Answer

b. Swapping will increase the chance of winning.

In the Monte Hall problem, swapping the choice after one of the doors is revealed to be empty actually increases the chance of winning from the initial probability of 1/3 to 2/3. This is a counterintuitive result, but it has been mathematically proven and demonstrated through simulations.

To explain why swapping increases the chance of winning, consider the following scenario: You initially choose one of three doors, and the host then reveals one of the remaining doors to be empty. At this point, you are left with your original choice and one other unopened door. If you stick with your original choice, you will win only if your initial choice was the correct door, which has a probability of 1/3. However, if you switch to the other unopened door, you will win if your initial choice was wrong, which has a probability of 2/3.

Therefore, swapping the choice after one of the doors is revealed to be empty increases the chance of winning from 1/3 to 2/3.

## What is the correct way to initialize a dictionary?

a. D = {a-10, b-20, c-30}b. D = {‘a’-10, ‘b’-20, ‘c’-30}

c. D = {a:10, b:20, c:30}

d. D = {‘a’:10, ‘b’:20, ‘c’:30}

## Answer

d. D = {‘a’:10, ‘b’:20, ‘c’:30}

**Example:**

dict = {'X': 1, 'Y': 2, 'Z': 4}

print(dict)

Output:

{'X': 1, 'Y': 2, 'Z': 4}

## What is the correct syntax to get all the keys only from a dictionary d?

a. d.key()b. d.item()

c. d.value()

d. d.keys()

## Answer

d. d.keys()

The keys() method in Python returns a list of all the keys in the dictionary.

## Which of the following is valid?.

a. D = {'a': {'a': 10}, 'b': 10}b. D = {'a': 'a': 10, 'b': 10}

c. D = {'a': {'a': 10}, 'b': {'b': 10}}

d. D = {'a': 'a': 10, 'b': 'b': 10}

## Answer

a. D = {'a': {'a': 10}, 'b': 10},

c. D = {'a': {'a': 10}, 'b': {'b': 10}}

Option 1:

D = {'a': {'a': 10}, 'b': 10}

This dictionary has two key-value pairs. The first key is 'a', and its corresponding value is another dictionary {'a': 10}. The second key is 'b', and its corresponding value is the integer 10.

Option 2:

D = {'a': 'a': 10, 'b': 10}
This option is not valid because the syntax is incorrect. If you want to have nested dictionaries, you need to use the curly braces {} to indicate a dictionary. The correct way to write the first key-value pair would be:

D = {'a': {'a': 10}, 'b': 10}

Option 3:

D = {'a': {'a': 10}, 'b': {'b': 10}}

This dictionary has two key-value pairs. The first key is 'a', and its corresponding value is another dictionary {'a': 10}. The second key is 'b', and its corresponding value is another dictionary {'b': 10}.

Option 4:

D = {'a': 'a': 10, 'b': 'b': 10}

This option is not valid because the syntax is incorrect. If you want to have key-value pairs, you need to use a colon : to separate the key and the value. The correct way to write the first key-value pair would be:

D = {'a': 10, 'b': 10}

## For bubble sort, which of the following statements is true?

a. If the list is sorted, the algorithm won’t work.b. In each iteration consecutive pairs of elements are compared with each other.

c. Every element is compared with every other element in the list in each iteration.

d. Swapping never happens in bubble sort.

## Answer

b. In each iteration consecutive pairs of elements are compared with each other.

The statement "In each iteration consecutive pairs of elements are compared with each other" is true for bubble sort.

Bubble sort is a simple sorting algorithm that works by repeatedly swapping adjacent elements if they are in the wrong order. In each iteration, the algorithm compares consecutive pairs of elements in the list and swaps them if they are in the wrong order, effectively "bubbling" the larger elements to the top of the list. This process is repeated until the list is fully sorted.

If the list is already sorted, bubble sort will still work, but it will take unnecessary iterations to confirm that no swaps were made, resulting in a worst-case time complexity.

It is not true that every element is compared with every other element in the list in each iteration. The algorithm only compares adjacent elements in each iteration.

It is also not true that swapping never happens in bubble sort. Swapping is the fundamental operation in bubble sort, as it is the mechanism by which the algorithm moves larger elements towards the end of the list.

## Which error is faced while accessing an element that is not there in a dictionary?

a. KeyErrorb. IndexError

c. RunTimeError

d. ValueError

## Answer

a. KeyError

The error faced while accessing an element that is not there in a dictionary is a KeyError.

A KeyError occurs when you try to access a key that does not exist in a dictionary. It can be raised in the following scenarios:

When you try to access a key that does not exist in the dictionary using the square bracket notation (e.g., my_dict['non_existent_key']).
When you try to access a key that does not exist in the dictionary using the .get() method without specifying a default value (e.g., my_dict.get('non_existent_key')).

In contrast, an IndexError occurs when you try to access an element of a sequence (e.g., a list or a tuple) using an index that is out of range. A ValueError occurs when you pass an invalid argument to a function. A RunTimeError is a general error that can occur at runtime for various reasons, such as a syntax error or a logical error in your code.

## In dictionaries, d.items() will return _

a. Pairs of all (key, value) together.b. All (keys) and (values) separately.

c. All (values) and (keys) separately.

d. Pairs of all (value, key) together.

## Answer

a. Pairs of all (key, value) together.

In dictionaries, d.items() will return pairs of all (key, value) together.

items() method will return the list with all dictionary keys with values.

## The Joy of Computing using Python - Course | NPTEL - All asignment

Disclaimer:

"This page contains multiple choice questions (MCQs) related to The Joy of Computing using Python . The answers to these questions are provided for educational and informational purposes only.These answers are provided only for the purpose to help students to take references. This website does not claim any surety of 100% correct answers. So, this website urges you to complete your assignment yourself."

## 0 Comments