Module Bank T1
Module Bank T1
Question: 1
a. Develop an algorithm, flowchart and Python Script to create a list of first 15 natural
numbers using for loop.
b. Develop an algorithm, flowchart and Python Script to input 15 numbers into a list and
arrange the numbers in ascending order.
Note: The list may contain duplicates.
c. For the given a list of integers from above question. Develop a program to find the
following.
i) Sum of the numbers in the list
ii) Product of the numbers in the list
iii) Median of the list (Note: The list size may be an even number or an odd
number)
iv) Mode of the list
d. For the List of Integers taken from the question b. apply the following operations
i) Convert the list of integers into a matrix list of 3 rows and 5 columns.
ii) Calculate the row wise sum of elements and columns wise of elements in the
matrix and print them.
Example:
Input:
List =[ 10,12,15,85,41,62,75,32,7,4,89,12,10,14,74]
Output:
Matrix=[[10,12,15,85,41],[62,75,32,7,4],[89,12,10,14,74]]
Sum_row1=163
Sum_row2=180
Sum_row3=199
Sum_column1=161
Sum_Column2=101
Sum_Column3=57
Sum_Column4=106
Sum_Column5=119
Question-2
a. Develop a Python script to print the first digit and last digit of a number given as input
b. Create a Python program to input the last four digits of your roll no and check whether
the number formed is a palindrome or not.
c. Develop a Python program that accepts a sequence of comma-separated numbers
from the user and generates a list and a tuple of those numbers.
Sample data : 3, 5, 7, 23
Output :
List : ['3', ' 5', ' 7', ' 23']
Tuple : ('3', ' 5', ' 7', ' 23')
d. Create a python program to find the row sums and column sums of a given matrix.
Given an m x n matrix, return all elements of the matrix in spiral order.
Example 1:
Question- 4
a. Develop a Python script to check if a given integer is prime or not using while loop.
b. Create a python program to print all the factors of a number using while loop.
c. Develop a Python program to test if a list contains elements in a Range.
Example:
Input:
a = [3, 8, 12, 18, 25], range 10,20
Output:
True
Explanation: If there is at least one number in the range from 10 to 20,
the result is true. In this case, the first number 3 is in the range. Hence,
no further testing, and declare the result as true.
d. Given an array of integers nums and an integer target, return indices of the two
numbers such that they add up to target.
You may assume that each input would have exactly one solution, and you may
not use the same element twice.
You can return the answer in any order.
Example 1:
Input: nums = [2,7,11,15], target = 9
Output: [0,1]
Explanation: Because nums[0] + nums[1] == 9, we return [0, 1].
Example 2:
Input: nums = [3,2,4], target = 6
Output: [1,2]
Example 3:
Input: nums = [3,3], target = 6
Output: [0,1]
Question 5
a. Develop a python to take two strings as input and convert each string into a list, tuple
and set and display them.
b. Create a python script to compare the above two strings using membership and
identity operators and print the output if both are identical or not.
c. You are given an array of strings words (0-indexed).
In one operation, pick two distinct indices i and j, where words[i] is a non-
empty string, and move any character from words[i] to any position in
words[j].
Return true if you can make every string in words equal using any number of
operations, and false otherwise.
Example 1:
Input: words = ["abc","aabc","bc"]
Output: true
Explanation: Move the first 'a' in words[1] to the front of words[2],
to make words[1] = "abc" and words[2] = "abc".
All the strings are now equal to "abc", so return true.
Example 2:
Input: words = ["ab","a"]
Output: false
Explanation: It is impossible to make all the strings equal using the operation.
Constraints:
1 <= words.length <= 100
1 <= words[i].length <= 100
words[i] consists of lowercase English letters.
d. You are given a 0-indexed array of string words and two integers left and right.
A string is called a vowel string if it starts with a vowel character and ends with
a vowel character where vowel characters are 'a', 'e', 'i', 'o', and 'u'.
Return the number of vowel strings words[i] where i belongs to the inclusive
range [left, right].
Example 1:
Input: words = ["are","amy","u"], left = 0, right = 2
Output: 2
Explanation:
- "are" is a vowel string because it starts with 'a' and ends with 'e'.
- "amy" is not a vowel string because it does not end with a vowel.
- "u" is a vowel string because it starts with 'u' and ends with 'u'.
The number of vowel strings in the mentioned range is 2.
Example 2:
Input: words = ["hey","aeo","mu","ooo","artro"], left = 1, right = 4
Output: 3
Explanation:
- "aeo" is a vowel string because it starts with 'a' and ends with 'o'.
- "mu" is not a vowel string because it does not start with a vowel.
- "ooo" is a vowel string because it starts with 'o' and ends with 'o'.
- "artro" is a vowel string because it starts with 'a' and ends with 'o'.
The number of vowel strings in the mentioned range is 3.
Constraints:
1 <= words.length <= 1000
1 <= words[i].length <= 10
words[i] consists of only lowercase English letters.
0 <= left <= right < words.length
Question: 6
a. Develop a Python script to print the Alphabets A to Z and a to z using for loop.
b. Arun has X cones and Y scoops of ice cream. Each ice cream cone requires exactly one cone
and one scoop of ice cream.
Your task is to develop a python program to determine the maximum number of ice cream
cones Arun can make with the available ingredients.
Input Format
Input will contain two integers XX and YY - the number of cones and ice cream scoops,
respectively.
Output Format
Output the maximum number of ice cream cones Chef can make.
Constraints
1≤X≤100
1≤Y≤100
Sample 1:
Input: 10 5
Output 5
Explanation:
Arun has 10 cones and 5 scoops of ice cream. Chef can make a maximum of 5 ice cream cones.
Question 7
a. Create a python program to print the first letter of your name as a pattern of size 5 rows
and 5 columns using ‘*’ symbol.
b. Develop a python program to count the number of vowels and consonants in the given
input string.
c. Given a string word, compress it using the following algorithm:
Begin with an empty string comp. While word is not empty, use the following
operation:
Remove a maximum length prefix of word made of a single character c
repeating at most 9 times.
Append the length of the prefix followed by c to comp.
Return the string comp.
Example 1:
Input: word = "abcde"
Output: "1a1b1c1d1e"
Explanation:
Initially, comp = "". Apply the operation 5 times, choosing "a", "b", "c", "d",
and "e" as the prefix in each operation.
For each prefix, append "1" followed by the character to comp.
Example 2:
Input: word = "aaaaaaaaaaaaaabb"
Output: "9a5a2b"
Explanation:
Initially, comp = "". Apply the operation 3 times, choosing "aaaaaaaaa",
"aaaaa", and "bb" as the prefix in each operation.
For prefix "aaaaaaaaa", append "9" followed by "a" to comp.
For prefix "aaaaa", append "5" followed by "a" to comp.
For prefix "bb", append "2" followed by "b" to comp.
Constraints:
1 <= word.length <= 2 * 105
word consists only of lowercase English letters.
d. Given an array of unique strings words, return all the word squares you can build
from words. The same word from words can be used multiple times. You can
return the answer in any order.
A sequence of strings forms a valid word square if the kth row and column
read the same string, where 0 <= k < max(numRows, numColumns).
For example, the word sequence ["ball","area","lead","lady"] forms a word
square because each word reads the same both horizontally and vertically.
Example 1:
Input: words = ["area","lead","wall","lady","ball"]
Output: [["ball","area","lead","lady"],["wall","area","lead","lady"]]
Explanation:
The output consists of two word squares. The order of output does not matter
(just the order of words in each word square matters).
Example 2:
Input: words = ["abat","baba","atan","atal"]
Output: [["baba","abat","baba","atal"],["baba","abat","baba","atan"]]
Explanation:
The output consists of two word squares. The order of output does not matter
(just the order of words in each word square matters).
Question 8
Question 10
a. Develop a python program to input two strings and check if the 2 nd string is a
permutation of the 1st string or not.
b. Develop a python script to check if a given string is palindrome or not and print all
the possible permutations of the string.
c. Develop a program to remove all duplicates from a given list of strings and
return a list of unique strings. Use the Python set data type.
Example 1:
Original list of strings:
['foo', 'bar', 'abc', 'foo', 'qux', 'bar', 'baz']
List of strings after removing duplicates:
['abc', 'qux', 'foo', 'baz', 'bar']
Example 2:
Original list of strings:
['Python', 'Exercises', 'Practice', 'Solution', 'Exercises']
List of strings after removing duplicates:
['Solution', 'Python', 'Exercises', 'Practice']
d. Two strings are said to be complete if on concatenation, they contain all the 26
English alphabets. For example, “abcdefghi” and “jklmnopqrstuvwxyz” are
complete as they together have all characters from ‘a’ to ‘z’. We are given two
sets of sizes n and m respectively and we need to find the number of pairs that
are complete on concatenating each string from set 1 to each string from set 2.
Example: