Fun Assignment
Fun Assignment
Expected Output : 20
5. Write a Python function to calculate the factorial of a number (a non-negative integer). The function
accepts the number as an argument.
6. Write a Python function to check whether a number falls within a given range.
7. Write a Python function that accepts a string and counts the number
Expected Output :
8. Write a Python function that takes a list and returns a new list with distinct elements from the first
list.
Note : A prime number (or a prime) is a natural number greater than 1 and that has no positive divisors
other than 1 and itself.
10. Write a Python program to print the even numbers from a given list.
According to Wikipedia : In number theory, a perfect number is a positive integer that is equal to the
sum of its proper positive divisors, that is, the sum of its positive divisors excluding the number itself
(also known as its aliquot sum). Equivalently, a perfect number is a number that is half the sum of all of
its positive divisors (including itself).
Example : The first perfect number is 6, because 1, 2, and 3 are its proper positive divisors, and 1 + 2 + 3
= 6. Equivalently, the number 6 is equal to half the sum of all its positive divisors: ( 1 + 2 + 3 + 6 ) / 2 = 6.
The next perfect number is 28 = 1 + 2 + 4 + 7 + 14. This is followed by the perfect numbers 496 and 8128.
12. Write a Python function that checks whether a passed string is a palindrome or not.
Note: A palindrome is a word, phrase, or sequence that reads the same backward as forward, e.g.,
madam or nurses run.
13. Write a Python function that prints out the first n rows of Pascal's triangle.
Note : Pascal's triangle is an arithmetic and geometric figure first imagined by Blaise Pascal.
Pascal's triangle
Note : Pangrams are words or sentences containing every letter of the alphabet at least once.
For example : "The quick brown fox jumps over the lazy dog"
15. Write a Python program that accepts a hyphen-separated sequence of words as input
and prints the words in a hyphen-separated sequence after sorting them alphabetically.
16. Write a Python function to create and print a list where the values are the squares of
17. Write a Python program to create a chain of function decorators (bold, italic, underline etc.).
18. Write a Python program to execute a string containing Python code.
20. Write a Python program to detect the number of local variables declared in a function.
Sample Output:
21. Write a Python program that invokes a function after a specified period of time.
Sample Output:
4.0
10.0
158.42979517754858
1. Write a Python program to create a lambda function that adds 15 to a given number passed in as an
argument, also create a lambda function that multiplies argument x with argument y and prints the
result.
Sample Output:
25
48
2. Write a Python program to create a function that takes one argument, and that argument will be
multiplied with an unknown given number.
Sample Output:
[{'make': 'Nokia', 'model': 216, 'color': 'Black'}, {'make': 'Mi Max', 'model': '2', 'color': 'Gold'}, {'make':
'Samsung', 'model': 7, 'color': 'Blue'}]
[{'make': 'Nokia', 'model': 216, 'color': 'Black'}, {'make': 'Samsung', 'model': 7, 'color': 'Blue'}, {'make': 'Mi
Max', 'model': '2', 'color': 'Gold'}]
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Even numbers from the said list:
[2, 4, 6, 8, 10]
[1, 3, 5, 7, 9]
6. Write a Python program to square and cube every number in a given list of integers using Lambda.
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
7. Write a Python program to find if a given string starts with a given character using Lambda.
Sample Output:
True
False
8. Write a Python program to extract year, month, date and time using Lambda.
Sample Output:
2020-01-15 09:03:32.744178
2020
15
09:03:32.744178
9. Write a Python program to check whether a given string is a number or not using Lambda.
Sample Output:
True
True
False
True
False
True
True
True
[0, 1]
[0, 1, 1, 2, 3]
[0, 1, 1, 2, 3, 5]
5. Write a Python function to calculate the factorial of a number (a non-negative integer). The function
accepts the number as an argument.
6. Write a Python function to check whether a number falls within a given range.
7. Write a Python function that accepts a string and counts the number of upper and lower case letters.
Expected Output :
8. Write a Python function that takes a list and returns a new list with distinct elements from the first
list.
Sample List : [1,2,3,3,3,3,4,5]
9. Write a Python function that takes a number as a parameter and checks whether the number is prime
or not.
Note : A prime number (or a prime) is a natural number greater than 1 and that has no positive divisors
other than 1 and itself.
10. Write a Python program to print the even numbers from a given list.
According to Wikipedia : In number theory, a perfect number is a positive integer that is equal to the
sum of its proper positive divisors, that is, the sum of its positive divisors excluding the number itself
(also known as its aliquot sum). Equivalently, a perfect number is a number that is half the sum of all of
its positive divisors (including itself).
Example : The first perfect number is 6, because 1, 2, and 3 are its proper positive divisors, and 1 + 2 + 3
= 6. Equivalently, the number 6 is equal to half the sum of all its positive divisors: ( 1 + 2 + 3 + 6 ) / 2 = 6.
The next perfect number is 28 = 1 + 2 + 4 + 7 + 14. This is followed by the perfect numbers 496 and 8128.
12. Write a Python function that checks whether a passed string is a palindrome or not.
Note: A palindrome is a word, phrase, or sequence that reads the same backward as forward, e.g.,
madam or nurses run.
13. Write a Python function that prints out the first n rows of Pascal's triangle.
Note : Pascal's triangle is an arithmetic and geometric figure first imagined by Blaise Pascal.
Sample Pascal's triangle :
Pascal's triangle
Note : Pangrams are words or sentences containing every letter of the alphabet at least once.
For example : "The quick brown fox jumps over the lazy dog"
15. Write a Python program that accepts a hyphen-separated sequence of words as input and prints the
words in a hyphen-separated sequence after sorting them alphabetically.
16. Write a Python function to create and print a list where the values are the squares of numbers
between 1 and 30 (both included).
17. Write a Python program to create a chain of function decorators (bold, italic, underline etc.).
Sample Output:
21. Write a Python program that invokes a function after a specified period of time.
Sample Output:
4.0
10.0
158.42979517754858
1. Write a Python program to create a lambda function that adds 15 to a given number passed in as an
argument, also create a lambda function that multiplies argument x with argument y and prints the
result.
Sample Output:
25
48
2. Write a Python program to create a function that takes one argument, and that argument will be
multiplied with an unknown given number.
Sample Output:
[{'make': 'Nokia', 'model': 216, 'color': 'Black'}, {'make': 'Mi Max', 'model': '2', 'color': 'Gold'}, {'make':
'Samsung', 'model': 7, 'color': 'Blue'}]
[{'make': 'Nokia', 'model': 216, 'color': 'Black'}, {'make': 'Samsung', 'model': 7, 'color': 'Blue'}, {'make': 'Mi
Max', 'model': '2', 'color': 'Gold'}]
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
[2, 4, 6, 8, 10]
[1, 3, 5, 7, 9]
6. Write a Python program to square and cube every number in a given list of integers using Lambda.
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
7. Write a Python program to find if a given string starts with a given character using Lambda.
Sample Output:
True
False
8. Write a Python program to extract year, month, date and time using Lambda.
Sample Output:
2020-01-15 09:03:32.744178
2020
15
09:03:32.744178
9. Write a Python program to check whether a given string is a number or not using Lambda.
Sample Output:
True
True
False
True
False
True
True
True
[0, 1]
[0, 1, 1, 2, 3]
[0, 1, 1, 2, 3, 5]
11. Write a Python program to find the intersection of two given arrays using Lambda.
Original arrays:
[1, 2, 3, 5, 7, 8, 9, 10]
[1, 2, 4, 8, 9]
12. Write a Python program to rearrange positive and negative numbers in a given array using Lambda.
Original arrays:
13. Write a Python program to count the even and odd numbers in a given array of integers using
Lambda.
Original arrays:
[1, 2, 3, 5, 7, 8, 9, 10]
14. Write a Python program to filter a given list to determine if the values in the list have a length of 6
using Lambda.
Sample Output:
Monday
Friday
Sunday
15. Write a Python program to add two given lists using map and lambda.
Original list:
[1, 2, 3]
[4, 5, 6]
[5, 7, 9]
16. Write a Python program to find the second lowest total marks of any student(s) from the given
names and marks of each student using lists and lambda. Input the number of students, the names and
grades of each student.
Name: S ROY
Grade: 1
Name: B BOSE
Grade: 3
Name: N KAR
Grade: 2
Name: C DUTTA
Grade: 1
Name: G GHOSH
Grade: 1
[['S ROY', 1.0], ['B BOSE', 3.0], ['N KAR', 2.0], ['C DUTTA', 1.0], ['G GHOSH', 1.0]]
Names:
N KAR
17. Write a Python program to find numbers divisible by nineteen or thirteen from a list of numbers
using Lambda.
Orginal list:
[19, 65, 57, 39, 152, 639, 121, 44, 90, 190]
18. Write a Python program to find palindromes in a given list of strings using Lambda.
Orginal list of strings:
List of palindromes:
['php', 'aaa']
19. Write a Python program to find all anagrams of a string in a given list of strings using Lambda.
20. Write a Python program to find the numbers in a given string and store them in a list. Afterward,
display the numbers that are longer than the length of the list in sorted form. Use the lambda function
to solve the problem.
20 23 56
21. Write a Python program that multiplies each number in a list with a given number using lambda
functions. Print the results.
Given number: 2
Result:
4 8 12 18 22
22. Write a Python program that sums the length of a list of names after removing those that start with
lowercase letters. Use the lambda function.
Result:
16
23. Write a Python program to calculate the sum of the positive and negative numbers of a given list of
numbers using the lambda function.
Original list: [2, 4, -6, -9, 11, -12, 14, -5, 17]
24. Write a Python program to find numbers within a given range where every number is divisible by
every digit it contains.
Sample Output:
25. Write a Python program to create the next bigger number by rearranging the digits of a given
number.
Original number: 12
Original number: 10
26. Write a Python program to find a list with maximum and minimum length using lambda.
Original list:
[[0], [1, 3], [5, 7], [9, 11], [13, 15, 17]]
(1, [0])
27. Write a Python program to sort each sublist of strings in a given list of lists using lambda.
Original list:
28. Write a Python program to sort a given list of lists by length and value using lambda.
Original list:
[[2], [0], [1, 3], [0, 7], [9, 11], [13, 15, 17]]
[[0], [2], [0, 7], [1, 3], [9, 11], [13, 15, 17]]
29. Write a Python program to find the maximum value in a given heterogeneous list using lambda.
Original list:
['Python', 3, 2, 4, 5, 'version']
Maximum values in the said list using lambda:
30. Write a Python program to sort a given matrix in ascending order according to the sum of its rows
using lambda.
Original Matrix:
Sort the said matrix in ascending order according to the sum of its rows
Original Matrix:
Sort the said matrix in ascending order according to the sum of its rows
31. Write a Python program to extract a specified size of strings from a given list of string values using
lambda.
Original list:
['practice', 'solution']
32. Write a Python program to count float values in a mixed list using lambda.
Original list:
33. Write a Python program to check whether a given string contains a capital letter, a lower case letter,
a number and a minimum length using lambda.
['Valid string.']
34. Write a Python program to filter the height and width of students, which are stored in a dictionary
using lambda.
Original Dictionary:
{'Cierra Vega': (6.2, 70), 'Alden Cantrell': (5.9, 65), 'Kierra Gentry': (6.0, 68), 'Pierre Cox': (5.8, 66)}
35. Write a Python program to check whether a specified list is sorted or not using lambda.
Original list:
True
Original list:
False
36. Write a Python program to extract the nth element from a given list of tuples using lambda.
Original list:
[('Greyson Fulton', 98, 99), ('Brady Kent', 97, 96), ('Wyatt Knott', 91, 94), ('Beau Turnbull', 94, 98)]
37. Write a Python program to sort a list of lists by a given index of the inner list using lambda.
Original list:
[('Greyson Fulton', 98, 99), ('Brady Kent', 97, 96), ('Wyatt Knott', 91, 94), ('Beau Turnbull', 94, 98)]
Sort the said list of lists by a given index ( Index = 0 ) of the inner list
[('Beau Turnbull', 94, 98), ('Brady Kent', 97, 96), ('Greyson Fulton', 98, 99), ('Wyatt Knott', 91, 94)]
Sort the said list of lists by a given index ( Index = 2 ) of the inner list
[('Wyatt Knott', 91, 94), ('Brady Kent', 97, 96), ('Beau Turnbull', 94, 98), ('Greyson Fulton', 98, 99)]
38. Write a Python program to remove all elements from a given list present in another list using
lambda.
Original lists:
list2: [2, 4, 6, 8]
[1, 3, 5, 7, 9, 10]
39. Write a Python program to find the elements of a given list of strings that contain a specific substring
using lambda.
Original list:
Substring to search:
ack
['black']
Substring to search:
abc
[]
40. Write a Python program to find the nested list elements, which are present in another list using
lambda.
[[12, 18, 23, 25, 45], [7, 11, 19, 24, 28], [1, 5, 8, 18, 15, 16]]
41. Write a Python program to reverse strings in a given list of string values using lambda.
Original lists:
42. Write a Python program to calculate the product of a given list of numbers using lambda.
3628800
4021.8599520000007
43. Write a Python program to multiply all the numbers in a given list using lambda.
Original list:
Original list:
[2, 4, 8, 8, 3, 2, 9]
44. Write a Python program to calculate the average value of the numbers in a given tuple of tuples
using lambda.
Original Tuple:
((10, 10, 10), (30, 45, 56), (81, 80, 39), (1, 2, 3))
Original Tuple:
((1, 1, -5), (30, -15, 56), (81, -60, -39), (-10, 2, 3))
45. Write a Python program to convert string elements to integers inside a given tuple using lambda.
Original tuple values:
46. Write a Python program to find the index position and value of the maximum and minimum values in
a given list of numbers using lambda.
Original list:
[12, 33, 23, 10.11, 67, 89, 45, 66.7, 23, 12, 11, 10.25, 54]
Index position and value of the maximum value of the said list:
(5, 89)
Index position and value of the minimum value of the said list:
(3, 10.11)
47. Write a Python program to sort a given mixed list of integers and strings using lambda. Numbers
must be sorted before strings.
Original list:
48. Write a Python program to sort a given list of strings (numbers) numerically using lambda.
Original list:
Original list:
[3, 4, 5, 8, 0, 3, 8, 5, 0, 3, 1, 5, 2, 3, 4, 2]
{3: 4, 4: 2, 5: 3, 8: 2, 0: 2, 1: 1, 2: 2}
50. Write a Python program to remove specific words from a given list using lambda.
Original list:
Remove words:
['orange', 'black']
51. Write a Python program to find the maximum and minimum values in a given list of tuples using the
lambda function.
[('V', 62), ('VI', 68), ('VII', 72), ('VIII', 70), ('IX', 74), ('X', 65)]
(74, 62)
52. Write a Python program to remove None values from a given list using the lambda function.
Original list:
1. Write a Python program to triple all numbers in a given list of integers. Use Python map.
2. Write a Python program to add three given lists using Python map and lambda.
3. Write a Python program to listify the list of given strings individually using Python map.
4. Write a Python program to create a list containing the power of said number in bases raised to the
corresponding number in the index using Python map.
5. Write a Python program to square the elements of a list using the map() function.
6. Write a Python program to convert all the characters into uppercase and lowercase and eliminate
duplicate letters from a given sequence. Use the map() function.
7. Write a Python program to add two given lists and find the difference between them. Use the map()
function.
8. Write a Python program to convert a given list of integers and a tuple of integers in a list of strings.
9. Write a Python program to create a new list taking specific elements from a tuple and convert a string
value to an integer.
10. Write a Python program to compute the square of the first N Fibonacci numbers, using the map
function and generate a list of the numbers.
11. Write a Python program to compute the sum of elements of an array of integers. Use the map()
function.
12. Write a Python program to find the ratio of positive numbers, negative numbers and zeroes in an
array of integers.
13. Write a Python program to count the same pair in two given lists. use map() function.
14. Write a Python program to interleave two lists into another list randomly. Use the map() function.
15. Write a Python program to split a given dictionary of lists into list of dictionaries using the map
function.
16. Write a Python program to convert a given list of strings into a list of lists using the map function.
17. Write a Python program to convert a given list of tuples to a list of strings using the map function.