Nalanda Python Assignment Day-1 Ans
Nalanda Python Assignment Day-1 Ans
Indian pin code. Consider a valid pin code is any string consisting of exactly 6 digits.
2) Write a function is_member() that takes a value (i.e. a number, string, etc) x and a list of values a, and
returns True if x is a member of a, False otherwise. (Note that this is exactly what the in operator does,
but for the sake of the exercise you should pretend Python did not have this operator.)
3) Define a function overlapping() that takes two lists and returns True if they have at least one member in
common, False otherwise. You may use your is_member() function, or the in operator, but for the sake
of the exercise, you should (also) write it using two nested for-loops.
4) Write a program that maps a list of words into a list of integers representing the lengths of the
corresponding words.
5) Write a function find_longest_word() that takes a list of words and returns the length of the longest one.
6) Write a version of a palindrome recognizer that also accepts phrase palindromes such as "Go hang a
salami I'm a lasagna hog.", "Was it a rat I saw?", "Step on no pets", "Sit on a potato pan, Otis", "Lisa
Bonet ate no basil", "Satan, oscillate my metallic sonatas", "Rise to vote sir", or the exclamation
"Dammit, I'm mad!". Note that punctuation, capitalization, and spacing are usually ignored.
7) Write a function char_freq() that takes a string and builds a frequency listing of the characters contained
in it. Represent the frequency listing as a Python dictionary. Try it with something like
char_freq("abbabcbdbabdbdbabababcbcbab").
8) Write a python program that prints the frequency of all the unique words. You can have a list of words
or you can take data from the user.
9) Write a python function to test, if a given number (passed as argument) is a perfect number
(https://en.wikipedia.org/wiki/Perfect_number)
10) Define a function reverse() that computes the reversal of a string. For example, reverse("I am testing")
should return the string "gnitset ma I".
12) Define a function is_palindrome() that recognizes palindromes (i.e. words that look the same written
backwards). For example, is_palindrome("radar") should return True.
13) "99 Bottles of Beer" is a traditional song in the United States and Canada. It is popular to sing on long
trips, as it has a very repetitive format which is easy to memorize, and can take a long time to sing. The
song's simple lyrics are as follows:
Your task here is write a Python program capable of generating all the verses of the song.
14) Write a function which accepts a string and returns a list of all possible permutations of the given string
in python.
15) Define a simple "spelling correction" function correct() that takes a string and sees to it that 1) two or
more occurrences of the space character is compressed into one, and 2) inserts an extra space after a
period if the period is directly followed by a letter. E.g. correct("This is very funny and cool.Indeed!")
should return "This is very funny and cool. Indeed!".