[go: up one dir, main page]

0% found this document useful (0 votes)
23 views13 pages

Module Bank T1

The document contains a comprehensive question bank for a programming module, covering various topics such as algorithms, flowcharts, and Python scripts. It includes tasks related to lists, matrices, string manipulations, and mathematical operations, requiring the development of scripts for specific functionalities. Each question is structured to guide the learner through practical coding exercises, enhancing their programming skills.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views13 pages

Module Bank T1

The document contains a comprehensive question bank for a programming module, covering various topics such as algorithms, flowcharts, and Python scripts. It includes tasks related to lists, matrices, string manipulations, and mathematical operations, requiring the development of scripts for specific functionalities. Each question is structured to guide the learner through practical coding exercises, enhancing their programming skills.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Module 1 T1 Question Bank

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:

Input: matrix = [[1,2,3],[4,5,6],[7,8,9]]


Output: [1,2,3,6,9,8,7,4,5]
Example 2:

Input: matrix = [[1,2,3,4],[5,6,7,8],[9,10,11,12]]


Output: [1,2,3,4,8,12,11,10,9,5,6,7]
Question :3
a. Develop a python script to calculate the factorial of a number given as a input.
b. Sita want to print the factorials of the first 10 natural numbers can you develop a python
program to perform the task.
c. Develop a Python program to find the second smallest number in a list.
Note: The list may contain duplicates. Your program should consider the
following.
 List must contain two or more numbers
If there are only two numbers and if they not are equal then return the second
smallest, otherwise none
d. You are given two 2D integer arrays, items1 and items2, representing two sets of
items. Each array items has the following properties:
items[i] = [valuei, weighti] where valuei represents the value and weighti
represents the weight of the ith item.
The value of each item in items is unique.
Return a 2D integer array ret where ret[i] = [valuei, weighti], with weighti
being the sum of weights of all items with value valuei.
Note: ret should be returned in ascending order by value.
Example 1:
Input: items1 = [[1,1],[4,5],[3,8]], items2 = [[3,1],[1,5]]
Output: [[1,6],[3,9],[4,5]]
Explanation:
The item with value = 1 occurs in items1 with weight = 1 and in items2 with
weight = 5, total weight = 1 + 5 = 6.
The item with value = 3 occurs in items1 with weight = 8 and in items2 with
weight = 1, total weight = 8 + 1 = 9.
The item with value = 4 occurs in items1 with weight = 5, total weight = 5.
Therefore, we return [[1,6],[3,9],[4,5]].
Example 2:
Input: items1 = [[1,1],[3,2],[2,3]], items2 = [[2,1],[3,2],[1,3]]
Output: [[1,4],[2,4],[3,4]]
Explanation:
The item with value = 1 occurs in items1 with weight = 1 and in items2 with
weight = 3, total weight = 1 + 3 = 4.
The item with value = 2 occurs in items1 with weight = 3 and in items2 with
weight = 1, total weight = 3 + 1 = 4.
The item with value = 3 occurs in items1 with weight = 2 and in items2 with
weight = 2, total weight = 2 + 2 = 4.
Therefore, we return [[1,4],[2,4],[3,4]].

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.

c. We can scramble a string s to get a string t using the following algorithm:


If the length of the string is 1, stop.
If the length of the string is > 1, do the following:
Split the string into two non-empty substrings at a random index, i.e., if the string is s,
divide it to x and y where s = x + y.
Randomly decide to swap the two substrings or to keep them in the same order. i.e.,
after this step, s may become s = x + y or s = y + x.
Apply step 1 recursively on each of the two substrings x and y.
Given two strings s1 and s2 of the same length, return true if s2 is a scrambled string of
s1, otherwise, return false.
Example 1:
Input: s1 = "great", s2 = "rgeat"
Output: true
Example 2:
Input: s1 = "abcde", s2 = "caebd"
Output: false
Example 3:
Input: s1 = "a", s2 = "a"
Output: true
Constraints:
s1.length == s2.length
1 <= s1.length <= 30
s1 and s2 consist of lowercase English letters.
d. You are given two strings s and t of equal length n. You can perform the following
operation on the string s:
Remove a suffix of s of length l where 0 < l < n and append it at the start of s.
For example, let s = 'abcd' then in one operation you can remove the suffix 'cd' and
append it in front of s making s = 'cdab'.
You are also given an integer k. Return the number of ways in which s can be
transformed into t in exactly k operations.
Since the answer can be large, return it modulo 109 + 7.
Example 1:
Input: s = "abcd", t = "cdab", k = 2
Output: 2
Explanation:
First way:
In first operation, choose suffix from index = 3, so resulting s = "dabc".
In second operation, choose suffix from index = 3, so resulting s = "cdab".
Second way:
In first operation, choose suffix from index = 1, so resulting s = "bcda".
In second operation, choose suffix from index = 1, so resulting s = "cdab".
Example 2:
Input: s = "ababab", t = "ababab", k = 1
Output: 2
Explanation:
First way:
Choose suffix from index = 2, so resulting s = "ababab".
Second way:
Choose suffix from index = 4, so resulting s = "ababab".
Constraints:
2 <= s.length <= 5 * 105
1 <= k <= 1015
s.length == t.length
s and t consist of only lowercase English alphabets.

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

a. Develop a Python program to remove duplicates from a list.


b. Develop a Python program to clone or copy a list.
c. You are given a large integer represented as an integer array digits, where each
digits[i] is the ith digit of the integer. The digits are ordered from most
significant to least significant in left-to-right order. The large integer does not
contain any leading 0's.
Increment the large integer by one and return the resulting array of digits.
Example 1:
Input: digits = [1,2,3]
Output: [1,2,4]
Explanation: The array represents the integer 123.
Incrementing by one gives 123 + 1 = 124.
Thus, the result should be [1,2,4].
Example 2:
Input: digits = [4,3,2,1]
Output: [4,3,2,2]
Explanation: The array represents the integer 4321.
Incrementing by one gives 4321 + 1 = 4322.
Thus, the result should be [4,3,2,2].
Example 3:
Input: digits = [9]
Output: [1,0]
Explanation: The array represents the integer 9.
Incrementing by one gives 9 + 1 = 10.
Thus, the result should be [1,0].
d. Given an unsorted integer array nums. Return the smallest positive integer that
is not present in nums.
You must implement an algorithm that runs in O(n) time and uses O(1)
auxiliary space.
Example 1:
Input: nums = [1,2,0]
Output: 3
Explanation: The numbers in the range [1,2] are all in the array.
Example 2:
Input: nums = [3,4,-1,1]
Output: 2
Explanation: 1 is in the array but 2 is missing.
Example 3:
Input: nums = [7,8,9,11,12]
Output: 1
Explanation: The smallest positive integer 1 is missing.
Question 9

a. Develop a program to extract tuples having K digit elements.


Example 1:
Input : test_list = [(54, 2), (34, 55), (222, 23), (12, 45), (78, )], K = 2
Output : [(34, 55), (12, 45), (78,)]
Explanation : All tuples have numbers with 2 digits.
Example 2:
Input : test_list = [(54, 2), (34, 55), (222, 23), (12, 45), (782, )], K = 3
Output : [(782,)]
Explanation : All tuples have numbers with 3 digits.
b. Develop a program to extract symmetric tuples.
Example 1:
Input : test_list = [(6, 7), (2, 3), (7, 6)]
Output : {(6, 7)}
Example 2:
Input : test_list = [(6, 7), (2, 3)]
Output : {}
c. Given two sets of numbers, Develop a Python program to find the missing
numbers in the second set as compared to the first and vice versa. Use the
Python set.
Example:
Original sets:
{1, 2, 3, 4, 5, 6}
{3, 4, 5, 6, 7, 8}
Missing numbers in the second set as compared to the first:
{1, 2}
Missing numbers in the first set as compared to the second:
{8, 7}
d. Develop a Python program to find all the anagrams and group them together
from a given list of strings. Use the Python data type.
Note: A word or phrase made by transposing the letters of another word or
phrase is called an anagram; The word "secure" is an anagram of "rescue."
Example 1:
Original list of strings:
['eat', 'cba', 'tae', 'abc', 'xyz']
Find and group all anagrams in the said list:
[['eat', 'tae'], ['cba', 'abc'], ['xyz']]
Example 2:
Original list of strings:
['restful', 'forty five', 'evil', 'over fifty', 'vile', 'fluster']
Find and group all anagrams in the said list:
[['restful', 'fluster'], ['forty five', 'over fifty'], ['evil', 'vile']]

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:

Input : set1[] = {"abcdefgh", "mycountryindia",


"lmnopqrst", "abc"}
set2[] = {"ijklmnopqrstuvwxyz",
"abcdefghijklmnopqrstuvwxyz",
"defghijklmnopqrstuvwxyz"}
Output : 7
The total complete pairs that are forming are:
"abcdefghijklmnopqrstuvwxyz"
"abcdefghabcdefghijklmnopqrstuvwxyz"
"abcdefghdefghijklmnopqrstuvwxyz"
" mycountryindiaabcdefghijklmnopqrstuvwxyz"
"lmnopqrstabcdefghijklmnopqrstuvwxyz"
"abcabcdefghijklmnopqrstuvwxyz"
"abcdefghijklmnopqrstuvwxyz"

You might also like