Hello everyone, we are came back with Nptel week 8 programming assignment of Joy Of Computing Using Python. In this article we will discuss the answers for week 8 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 Quiz 8 Assignment Answers
The Joy Of Computing Using Python Week 8 AssignmentÂ
Before going to the assignment, let us see the topics briefly which are present in week 8.The topics Present in this week are :Â
- Tuples - Python Data Structures
- Lottery Simulation - Profit Or Loss
- Image Processing - Enhance your image
- Facebook - Sentiment Analysis
- Anagrams
Tuples - Python Data Structures
A tuple in Python is an immutable collection of values, similar to a list. However, tuples cannot be modified once they are created. Tuples are defined using parentheses, with individual values separated by commas.
For example, here is a tuple with three elements:
my_tuple = (1, "hello", True)
Lottery Simulation - Profit Or Loss
You want to see whether, whether you can simulate the process of wining or loosing yeah in a game of gambling yeah and you want to see whether one can become rich or one undergo very losses, yes precisely I you see he is educated so if you help me with this I can assure to him that see you are not in the right path and this is what actually happening, I think this is possible but this is popularly called the gamblers rule in problem probability but that aside you want to see if we can simulate the enter process of gambling and try to figure out if someone can even win or not, of course we will win a few times, we will lose a lot of times let’s say we play here for one year’s time three sixty five days we would like to see whether we make a lot of money or not right?
Image Processing - Enhance your Images
ENHANCE YOUR IMAGES What is the first thing that you do after clicking pictures? Of course apply filters in order to enhance them, so let us now shift gears and explore a new technique to enhance images through our next joy image processing.
Anagrams
Anagrams are words or phrases that are formed by rearranging the letters of another word or phrase. For example, the word "listen" and "silent" are anagrams of each other, as are "debit card" and "bad credit". Anagrams are often used in word games, puzzles, and cryptography, and can be a fun way to test your vocabulary and problem-solving skills.
Facebook - Sentiment Analysis
FACEBOOK SENTIMENT ANALYSIS Apart from sleeping, working and eating what else do we do in our day to day life? Well my answer would be Face booking. So let us try to explore Facebook with our next joy Facebook sentiment analysis.
Programming Assignment
Q1. Given a Tuple T, create a function square T that accepts one argument and returns a tupleÂ
    containing similar elements given in tuple T and its squares 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.
Code:Â Â
def squareT(T):Â return(T+tuple([i*i for i in T])){codeBox}
Q2. 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 _ .
Code:Â
def replaceV(S):Â vowels=list("aeiouAEIOU")Â L=list(S)Â for i in range(len(L)-2):Â Â if L[i] in vowels and L[i+1] in vowels and L[i+2] in vowels:Â Â Â L[i]='*'Â Â Â L[1+i]="*"Â Â Â L[i+2]="*"Â Â Â i+=2Â return("".join(L).replace("***","_"))Âprint(replaceV(input()),end=""){codeBox}
Q3. 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.)
Code:
L=[int(i) for i in input().split()]A=[]B=[]for i in L:Â ÂÂ if i==0:Â Â A.append(0)Â else:Â Â B.append(i)print(B+A,end=""){codeBox}
Conclusion:Â
I Request everyone to revisit the website on/before to last date for any re-verification of answers.
Â
If you have any queries, contact us. I am very thankful to answer you.
Â
NOTE:Â I'm answering these questions to the best of my knowledge.