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

ABOUT THE COURSE :
Pic

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 8 Assignment Solutions :-

Q1) Which of the following is not true about Stylometry Analysis?
a) It is the quantitative study of literature style
b) It is based on the observation that the authors tend to write in relatively consistent and recognizable ways
c) any two people may have the same vocabulary
d) It is a tool to study a variety of questions involving style of writing

Answer :- (cany two people may have the same vocabulary 

Q2)  Which of the following is not true about tuples in python?
a) Tuple consumes less memory
b) Tuples are immutable
c) Tuple supports item deletion
d) Tuples does not support modification

Answer :- (c) Tuple supports item deletion 

Q3)What is the output of the following code snippet in python?
name =(’kiran’,’bhushan’,’madan’)
print (name[-1])
a) invalid syntax
b) tuple index out of range
c) prints nothing
d) madan

Answer :- (d) madan 

Q4) Strings in python can be created using
a) single quotes
b) double quotes
c) triple quotes
d) only A and B
e) A, B and C

Answer :- (e A, B and C 

Q5)Networkx in python is used for which of the following operation(s)?
a) Visualizing social network
b) Analyzing social networks
c) Generate social network
d) All of the above
e) None of the above

Answer :- (dAll of the above 

Q6)  Which of the following will generate a complete graph in python using the networkx package?
a) Graph = nx.gnp random graph(25,0.5)
b) Graph = nx.gnp random graph(25,1.0)
c) Graph = nx.gnp random graph(25,0.25)
d) Graph = nx.gnp random graph(25,0.75)

Answer :- (b) Graph = nx.gnp random graph(25,1.0) 

Q7) Which of the following method will return the RBG value of a pixel in python?
a) getpixel()
b) RBGvalue()
c) pixelValue()
d) none of the above

Answer :- (a) getpixel() 

Q8)  The degree of separation of a complete graph with n nodes is always
a) n
b) n-1
c) 1 
d) 6

Answer :- (c

Q9) Which of the following is true about six degrees of separation?
a) the minimum degree of separation of any node in the network is 6
b) the maximum degree of separation of any node in the network is 6
c) the average degree of separation of the nodes in the network is 6
d) the degree of separation of every node in the network is 6

Answer :- (c) the average degree of separation of the nodes in the network is 6 

Q10) What is the output of the following code?
Week 8

a) ['Have nice day, my friend!!! Programming in Python is fun']
b) ['Have nice day, my friend!!!', 'Programming in Python is fun']
c) 'Have nice day, my friend!!!'
   'Programming in Python is fun
d) Error

Answer :- (b) ['Have nice day, my friend!!!', 'Programming in Python is fun'] 

 Week 8 Programming Assignment 1 :- 

Given a Tuple T, create a function squareT that accepts one argument and returns a tuple containing similar elements given in tuple T and its sqaures in sequence.

Input:

(1,2,3)

Output :

(1,2,3,1,4,9)
Week 8 Programming Assignment 1
def squareT(T):
  return(T+tuple([i*i for i in T]))

 Week 8 Programming Assignment 2 :- 

Given a string S, write a function replaceV that accepts a string and replace the occurrences of 3 consecutive vowels with _ in that string. Make sure to return and print the answer string.

Input:

aaahellooo

Output:

_hell_
Week 8 Programming Assignment 2
def isvowel(ch):
    v = 'AEIOUaeiou'
    if ch in v:
        return True
    else:
        return False

def replaceV(s):
    n = len(s)
    ans = ''
    i=0
    while(i<n-2):
        if isvowel(s[i]) and isvowel(s[i+1]) and isvowel(s[i+2]):
            ans = ans+'_'
            i = i+3
        else:
            ans = ans+s[i]
            i = i+1
    return ans+s[i:]

S = input()
print(replaceV(S),end='')

 Week 8 Programming Assignment 3 :- 

Write a program that take list L as an input and shifts all zeroes in list L towards the right by maintaining the order of the list. Also print the new list.

Input:

[0,1,0,3,12]

Output:

[1,3,12,0,0]

Week 8 Programming Assignment 3
L = list(map(int, input().split()))

zeroes = L.count(0)
i = 0
while i < len(L)-zeroes:
    if L[i] == 0:
        L.pop(i)
        L.append(0)
        i -= 1
    i += 1
print(L,end="")

Join us :