# The Joy of Computing using Python | Week 8

Session: JULY-DEC 2023

Course Name:  The Joy of Computing using Python

#### These are answers of The Joy of Computing using Python Assignment 8 Answers

Q1. What is the correct initialisation of tuples?
Dates = [12,23,3,4]
Dates = (12,23,3,4)
Dates = {12,23,3,4}
Both B and C

Q2. What operations can be done on tuples?
Tuples are appendable.
We can delete a value from tuples.
Both A and B.
We can count the number of instances of an element.

Answer: We can count the number of instances of an element.

Q3. What will be the output of the following code?
1,2,3,4,5
5,4,3,2,1
5,4,3,2
1,2,3,4

These are answers of The Joy of Computing using Python Assignment 8 Answers

Q4. What will be the output of the following code?
gbdfcppl
ezbdannj
ytvxuhhd

Q5. When the following program will clap?
When both players will enter the same letters.
When player 2 will enter the next letter with respect to player 1.
When player 1 will enter the next letter with respect to player 2.
It will never clap.

Answer: When player 2 will enter the next letter with respect to player 1.

Q6. Which statement is correct about the following program?
The graph will go up when guess and pick are the same.
The graph will go down when guess and pick are the same.
The graph will go up when guess and pick are not the same.
Both B and C

These are answers of The Joy of Computing using Python Assignment 8 Answers

Q7. What does NLTK do?
Helps to work with human language data.
Helps to convert machine data into human language.
Helps to work on gibberish language.
Helps to translate dog language into human language.

Answer: Helps to work with human language data.

Q8. What is the output of the following code?
[‘!’, ‘e’, ‘e’, ‘e’, ‘h’, ‘h’, ‘r’, ‘t’, ‘y’]
[‘h’, ‘e’, ‘y’, ‘!’, ‘t’, ‘h’, ‘e’, ‘r’, ‘e’]
[‘y’, ‘t’, ‘r’, ‘h’, ‘h’, ‘e’, ‘e’, ‘e’, ‘!’]
None of the above

Answer: [‘y’, ‘t’, ‘r’, ‘h’, ‘h’, ‘e’, ‘e’, ‘e’, ‘!’]

These are answers of The Joy of Computing using Python Assignment 8 Answers

Q9. While converting an image into black and white during enhancement you cannot convert it back into a colored image.
True
False

These are answers of The Joy of Computing using Python Assignment 8 Answers

Q10. How does vader help in sentiment analysis?
It calculates whether the statement is negative, positive or neutral.
It takes care of the intensity of a statement.
Both A and B
None of the above

These are answers of The Joy of Computing using Python Assignment 8 Answers

### The Joy of Computing using Python Programming Assignmnet

Question 1
Given a Tuple T, create a function squareT which accepts one argument and returns a tuple containing similar elements given in tuple T and its sqaures in sequence. Input and function call is already managed.
Input:
(1,2,3)
Output :
(1,2,3,1,4,9)
Explanation:
Tuple T contains (1,2,3) the output tuple contains the original elements of T that is 1,2,3 and its sqaures 1,4,9 in sequence.

Solution:

``````def squareT(T):
return(T+tuple([i*i  for i in T]))``````

These are answers of The Joy of Computing using Python Assignment 8 Answers

Question 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 the answer string.
Input:
aaahellooo
Output:
_hell_
Explanation:
Since aaa and ooo are consecutive 3 vowels therefor replaced by _ .

Solution:

``````vo = list('aeiou')+list('AEIOU')
def replaceV(s):
ans = ""
a = 0
while a < len(s) - 2:
if s[a] in vo and s[a + 1] in vo and s[a + 2] in vo:
a = a + 2
ans+="_"
else:
ans += s[a]
a += 1
ans += s[a:]
return(ans)``````

These are answers of The Joy of Computing using Python Assignment 8 Answers

Question 3
Given a list L, write a program to shift 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]
Explanation:
There are two zeroes in the list which are shifted to the right and the order of the list is also maintained. (1,3,12 are in order as in the old list.)

Solution:

``````G=list()
for i in L:
if i!=0:
G.append(i)
G+=*(len(L)-len(G))
print(G,end="")``````

These are answers of The Joy of Computing using Python Assignment 8 Answers

Session Jan-Apr 2023

Course Name:  The Joy of Computing using Python

#### Q1. Which of the following is not true about Stylometry Analysis?a. It is the quantitative study of literature styleb. It is based on the observation that the authors tend to write in relatively consistent and recognizable waysc. any two people may have the same vocabularyd. It is a tool to study a variety of questions involving style of writing

Answer: c. any 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?
print (name[-1])

a. invalid syntax
b. tuple index out of range
c. prints nothing

These are answers of The Joy of Computing using Python Assignment 8 Answers

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: d. All 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)

These are answers of The Joy of Computing using Python Assignment 8 Answers

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

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

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

These are answers of The Joy of Computing using Python Assignment 8 Answers

Q10. What is the output of the following code?

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’]

### The Joy of Computing using Python Programming Assignmnet

Question 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)
Explanation:
Tuple T contains (1,2,3) the output tuple contains the original elements of T that is 1,2,3 and its sqaures 1,4,9 in sequence.

Solution:

``````def squareT(T):
temp = list(T)
for i in T:
temp.append(i*i)
return tuple(temp)``````

These are answers of The Joy of Computing using Python Assignment 8 Answers

Question 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_
Explanation:
Since aaa and ooo are consecutive 3 vowels and therefor replaced by _ .

Solution:

``````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))``````

These are answers of The Joy of Computing using Python Assignment 8 Answers

Question 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]
Explanation:
There are two zeroes in the list which are shifted to the right and the order of the list is also maintained. (1,3,12 are in order as in the old list.)

Solution:

``````n = 10
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)``````

These are answers of The Joy of Computing using Python Assignment 8 Answers

More Nptel courses: http://13.235.254.184/nptel/

Session JUL-DEC 2022

#### Course name: The Joy of Computing Using Python

These are answers of The Joy of Computing using Python Assignment 8 Answers

Q1. Which of the following q43 the correct representation of tuples?
a) [1,2,3,4]
b) (1,2,3,4)
c) ((1), (2), (3), (4))
d) [, , , ]

Q2. Why gambling is not recommended?
a) Because you lose every time.
b) Because you win every time.
c) Because the loss amount is greater than the winning amount over time.
d) Because the winning amount is greater than the loss amount over time.

Answer: c) Because the loss amount is greater than the winning amount over time.

This is an assignment for The Joy of Computing using Python Week 8 Assignment

Q3. Which of the following programs will print the exact same word?

Q4. Using which of the following methods a person can store over a million images in small digital storage?
a) Decompression
b) Compression
c) Enhancement

These are answers of The Joy of Computing using Python Assignment 8 Answers

Q5. State True or False, A lot of information can be revealed from images by using the right kind of enhancement.
a) True
b) False

Q6. type(10) will return?
a) int
b) str
c) float
d) list

Q7. Which of the following pair of words are anagrams?
a) A gentleman, Elegant man
b) Cat, Arc
c) Looted, Toledo
d) Monasteries, Aman stories

These are answers of The Joy of Computing using Python Assignment 8 Answers

Q8. Using PIL how an image ‘img’ can be flipped?
a) img.flip()
b) img.rotate()
c) img.transpose()
d) img.turn()

Q9. What is the purpose of NLTK?
a) To process binary language.
b) To process foreign language.
c) To process human language.
d) To process only Hindi language

Answer: c) To process human language.

Q10. How does Vader help in sentiment analysis?
a) It calculates whether the statement is negative, positive, or neutral.
b) It takes care of the intensity of a statement.
c) Both A and B
d) None of the above

Answer: c) Both A and B

These are answers of The Joy of Computing using Python Assignment 8 Answers

## Programming Assignment

Question 1: Write a function cubeT that accepts a list L and returns a tuple containing cubes of elements of L.
Input
A tuple T
Output
Cube of T

Solution:

``//Code``

These are answers of The Joy of Computing using Python Assignment 8 Answers

Question 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 the answer string.
Input:
aaahellooo
Output:
_hell_

Solution:

These are answers of The Joy of Computing using Python Assignment 8 Answers

``//Code``

These are answers of The Joy of Computing using Python Assignment 8 Answers

Question 3 : Given a list L, write a program to shift 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]

Solution:

``//Code``

These are answers of The Joy of Computing using Python Assignment 8 Answers

More NPTEL Solution: http://13.235.254.184/nptel