Hello everyone, we are came back with Nptel week 5 programming assignment of Joy Of Computing Using Python. In this article we will discuss the answers fo week 5 assignment . Please Use these answers as reference, If any doubt arises feel free to comment in the comment section below. Then why Waiting, Come with us, Let us solve the programming assignment.Â
Also read:Â The Joy of computing using Python week 5 Quiz answersÂ
The Joy Of Computing Using Python Week 5 Programming AssignmentÂ
Before going into the answers of week 5 , let briefly see the what are the topics present in Week 5 :Â
- Introduction to dictionaries
- Speech To TextÂ
- Monte HallÂ
- Rock, Paper and ScissorÂ
- Sorting and SearchingÂ
Introduction to Dictionaries:Â
Speech to text :Â
Monte Hall:Â
Rock, Paper and Scissor:Â
Sorting and Searching:Â
Programming Assignment:
Let now see the Assignment Sums:Â
Q1. 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.
CODE:Â Â
import math
a = int(input())
b = int(input())Â
print(math.gcd(a,b),end=''){codeBox}
Â
Q2. 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.
CODE:Â Â
raja=[int(i) for i in input().split()]
rani=[int(i) for i in input().split()]Â
def dot_product(Romio, Juliet ):
 return(sum([Romio[i]*Juliet[i] for i in range(len(Romio))])) Â
print(dot_product(raja,rani),end=""){codeBox}
Q3.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. Â
CODE:Â Â
def largest_zero_streak(mystring):
  return(len(max(mystring.split('1'))))
s=input()
print(largest_zero_streak(s),end="")Â Â {codeBox}
Â
Also Read:Â The Joy Of Computing Using Python Week 5 Quiz Answers