The Joy of Computing Using Python Week 5 Solutions

The Joy of Computing using Python | NPTEL 2023 | Week 5 Assignment Solutions

ABOUT THE COURSE :
Week 5 Python

A fun filled whirlwind tour of 30 hrs, covering everything you need to know to fall in love with the most sought after skill of the 21st century. The course brings programming to your desk with anecdotes, analogies and illustrious examples. Turning abstractions to insights and engineering to art, the course focuses primarily to inspire the learner's mind to think logically and arrive at a solution programmatically. As part of the course, you will be learning how to practice and culture the art of programming with Python as a language. At the end of the course, we introduce some of the current advances in computing to motivate the enthusiastic learner to pursue further directions.

Course Status     :    Upcoming
Course Type        :    Elective
Duration               :    12 weeks
Start Date            :    23 Jan 2023
End Date              :    14 Apr 2023
Exam Date           :    29 Apr 2023 IST
Enrollment Ends :    30 Jan 2023

CRITERIA TO GET A CERTIFICATE :

Average assignment score = 25% of average of best 8 assignments out of the total 12 assignments given in the course.
Exam score = 75% of the proctored certification exam score out of 100

Final score = Average assignment score + Exam score

YOU WILL BE ELIGIBLE FOR A CERTIFICATE ONLY IF AVERAGE ASSIGNMENT SCORE >=10/25 AND EXAM SCORE >= 30/75. If one of the 2 criteria is not met, you will not get the certificate even if the Final score >= 40/100.

NOTE: Please note that there will not be an unproctored programming exam for this course this term.

The Joy of Computing using Python Week 5 Assignment Solutions :-

Q1) Binary search can be applied on ___.

a) Sorted list
b) Unsorted list
c) Both A and B
d) Any list with any elements

Answer :- (a) Sorted list 

Q2) Which of the following is a Waveform Audio File Format.

a) Wav
b) Wave
c) Wv
d) Waves

Answer :- (a), (b) 

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

a) speech_recognition
b) text_to_speech
c) speech_to_text
d) text_translate

Answer :- (a) speech_recognition 

Q4) 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 :- (bSwapping will increase the chance of winning. 

Q5) 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} 

Q6) 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 :- (dd.keys() 

Q7) 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), (c) 

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

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

a) KeyError
b) IndexError
c) RunTimeError
d) ValueError

Answer :- (a) KeyError 

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

 Week 5 Programming Assignment 1 :- 

Write a Python program that finds the Greatest Common Divisor (GCD) of two numbers. Your program should take two input numbers from the user, and use a function named 'gcd' to find the GCD of those two numbers. Your program should then print out the GCD of the two numbers as the output.    
Week 5 Programming Assignment 1
import math
a=int(input())
b=int(input())
print(math.gcd(a,b),end="")

 Week 5 Programming Assignment 2 :- 

Write a Python program that calculates the dot product of two lists containing the same number of elements. The program should take two lists of integers as input from the user, and then call a function named dot_product to find the dot product of the two lists. The dot_product function should take two lists a and b as input, and should return the dot product of those two lists.

Your program should first prompt the user to enter the two lists of integers, which should be entered as strings separated by spaces. Your program should then convert the input strings into lists of integers. Your program should then call the dot_product function with the two lists as arguments, and store the resulting dot product in a variable named result. Finally, your program should print out the dot product of the two lists as the output.

You can assume that the two input lists will always contain the same number of elements. Your program should output an error message and exit gracefully if the two lists have different lengths.

In your implementation, you should define the dot_product function using a loop to calculate the dot product of the two input lists.
Week 5 Programming Assignment 2
def dot_product(c, d ):
  return(sum([c[i]*d[i]  for i in range(len(c))]))   
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()] 
print(dot_product(a,b),end="")

 Week 5 Programming Assignment 3 :- 

Write a Python function that takes a string s as input and returns the length of the largest streak of 0s in the string. For example, if the input string is "10001000110000000001", the function should return 6.

Input :- The input string s is guaranteed to contain only 0s and 1s.

Output :-The function should return an integer, representing the length of the largest streak of 0s in the input string.
Your program should also print the result.
Week 5 Programming Assignment 3
def largest_zero_streak(a):
    m=max(a)
    l=len(m)
    return l
s=input()
t=s.split('1')
print(largest_zero_streak(t),end='')

Join us :       




Join Now


Previous Year Questions Now to Boost Your Exam Performance

LOADS OF LOGIC