PES UNIVERSITY, BENGALURU
UE25CS151A – PYTHON FOR COMPUTATIONAL PROBLEM SOLVING
SAMPLE LAB QUESTIONS
AY 2025-26
IMPORTANT TOPICS: LIST, STRING, DICTIONARIES, SETS, CONTROL STRUCTURES, PATTERN TYPE,
MATRIX BASED QUESTIONS
WRITING PART: 2 MARKS
EXECUTING THE CODE:3 MARKS
VIVA: 1 MARKS
TOTAL:6 MARKS
-------------------------------------------------------------------------------------------------------------------------------------------------------
1.
####1
###21
##321
#4321
54321
Write a program to get this pa ern
2.
Enter a 2D matrix and find the element of maximum value along with its posi on.
3.
Pa ern prin ng program.
Sample output:
Enter number of rows: 4
1
10
101
1010
4.
string duplicate characters
Enter the string: programming
5.
Take a list from the user.
Take the frequency from the user.
Whichever elements frequency on the list matches the frequency given by the user, those elements have to be
removed and the list has to be modified to only have the remaining elements.
6.
Convert the given input word into pigla n ( the cases for pigla n is specified in qs)
7.
interchange keys and values for a given dic onary and also check whether the given key is present or not
8.
Two lists will be given
add them and sort them
9.
check if a string is anagram or not(elegant man ….problem)
10.
1
12
123
1234
Pa ern type qn
11.
given a list remove duplicate elements and print remaining
12.
diamond pa ern by using (*)
13.
Write a program to know that whether the given number is armstrong number or not??
armstrong number means its sum of its cube root is same number
ex:Take 153 153=1^3+5^3+3^3
the program should be like this:
input:Enter the number:153
output:153 is an armstrong number
input:Enter the number:111
output:111 is not a armstong number
14.
Find the common integers in 2 lists without built in commands
15.
input the dic onary and interchange the keys and values of the dic onary and execute it
16.
Write a func on to add two numbers
17.
Write a program to get the frequencies of a given number in the input of the users number
18.
remove punctua on
input: Hello, World!
output : Hello world
19.
Enter inputs and save them in dict and name the data type and concatena on the inputs which are only string
20.
Take input for 2 numbers and find the Greatest Common Divisor for them
21.
the list had one more list inside it and i need to make a common list removing inside list
example:[[1,2],[3],[4,5]] --> [1,2,3,4,5]
22.
Take 2 lists as input from the user such that both lists have the same length.
Create a dic onary that is created such that the keys are taken from the first list and value are taken from the
second list
23.
Find factorial of number given by user
24.
Find the sum of n terms
25.
Fibbonacci series
26.
Check whether given string is palindrome or not
27.
take the input of integers seperated by spaces from the user
and count the frequency of each digit
eg:
Enter integers seperated by spaces: 2 4 2 8 8 9 9 9
2 => 2 mes
4 => 1 me
8 => 2 mes
9 => 3 mes
28.
Write a program which prints the second largest number in the give integer
Input:(22,20,4,60,99)
Output:(60)
29.
Take a string and find out like the character which was repeated the most if mul ple print any one
Ex
input "programming"
30.
Find the common elements of the 2 lists without using set() or intersec on
enter the first list=10 20 30 40 50
enter the second list= 30 40 60 80
common elements = [ 30 40]
31.
Frequency of each word (case sensi ve) from the input sentence ignoring the punctua on
32.
Create 2D matrix and output the transpose of the element
33.
take a string as input and remove the repeated characters keeping the first occunrance of the character
Eg : input = programming
output = progamin
34.
find the second largest number in a list
35.
Take input as a word from the user and converted into pig La n
In pig La n the first le er is put to the end and suffixed with ay
Eg Hello
Helloay
36.
Ask user to give order of the matrix and enter matrix values
now the problem statement was
find the minimum value among the matrix values and tell its rows and column
37.
given a list and a target value
find pairs in the list which add up to the target value
38.
Roach all the vowels in a strong with "*" symbols
39.
Write a program to check whether the given year is a leap year or not.
A leap should be divisible by 4 and if the year is an end of century year then it should be divisible by 400 (eg
1900, 2000)
40.
Use the Caesar cipher with a shi of '3'
The Caesar cipher shi s each le er in the input by a fixed number of posi ons in the alphabet
ex:
input =Hello World
Output = Khoor Zruog
41.
Accept a list from the user from which the even numbers in the list must be removed and the list without them
should be printed without using any of the lost func on and proper es
42.
Make a game without using dic onary, lists or sets... The game should be in 3d format , it should have over 99
levels without repea ng
43.
In a given 2d nested list (resembles a matrix )
Find the average of diagonal values
44.
Print the following series
by taking no. of rows as input from user.
1
23
456
7 8 9 10
11 12 13 14 15
45.
Given user input for two lists (key and value)
make a new dic onary and save all the key value pairs in it.
Print the output
Input: Key = ['1', '2', '3']
Value: ["One", "Two", "Three"]
Output:
Dic onary = {'1':"One", '2':"Two", '3':"Three"}
46.
Enter a list (string separated by spaces).
Input number of elements of list (n) and a value k (k < n).
Now remove the elements which occur exactly k mes in the list and print the modified list.
47.
Input a list and check whether its monotonic (strictly decreasing or increasing)
48.
Print the pa ern
1
121
12321
1234321
49.
Input a list from the user and split it into two if has even items or add one more item from user if it has odd
items and then split it.
50.
Take two dic onary as input
Create a dic onary which merges these two dic onaries and if there are common keys in both dic onary, add
the values of the common keys
Sample Input:
dict1={'a':10,'b':20,'c':30} dict2 = {'b':10 , 'c':15 , 'd':30} ;
Sample Output:
Merged Dic onary= {'a':10,'b':30,'c':45,'d':30}
51.
Enter a 2D 3×3 matrix and find the max element and posi on in the matrix.
52.
Write a code for the nth sequence
53.
Given a string check if its a palindrome or not
Ignore white spaces punctua on cases
Sample input: "A man, a plan , a canal: Panama"
Output: true
Replace all the vowels in the given string with asterisk. Take input string as-Beau ful Day
Output: false
54.
input a string from the user and find the frequency of each word and output them as a dic onary with the
words as keys and the frequency as the values
55.
Given a list of integers,
print a set with all even numbers removed,
Eg:
integers separated by space:10 15 20 25 30 35 40 45
output: [15,25,35,45]
56.
Ask the user to input a string. Also ask the user to input a posi ve integer .... This integer will act as a shi
value . For every character in the string we have to replace it by a le er that is ahead of it by its shi value .......
For example
if the input string is "Hello world"....... And the shi value is 1 .....
Then 'H' gets replaced by 'I'.... 'e' gets replaced by 'f' and so on......
The special character in case there doesnt get replaced
57.
Replace all the vowels in the given string with asterisk. Take input string as-Beau ful Day.
58.
write a program to input integers in a list, input a target number, search for pairs of numbers in the list which
add up to the sum(pairs should be in a list ,pair in tuple format)
59.
Take 2 different list from the user and print the common elements from them but without set() and
intersec on ()
60.
Take input of n and k such that n is the no of elements in the list and k being the occurrence give a modified list
such that the numbers with k occurrence gets deleted
61.
Input a list with duplicates and write a program to remove the duplicates in the list with altering the order of
the list.
Ex...
Input: [1 3 3 2 6 5 1]
Output: [1 3 2 6 5]
62.
Most frequent le er occuring in the input string.
63.
Input two dic onaries from the user, merge both into a new dic onary.
If there are two keys which are the same in both, add up the values of both and update the key and new value
in the new dic onary.
Eg:
Input: d1 = {'a':1,' 'b':2, 'c':3}
d2 = {'b':5, 'c':8, 'd': 10}
Output: {'a':1,'b':7,'c':11,'d':10}
64.
U are given a sentence, you should find the longest word in it and the number of le ers in the word
65.
Print a list containing non duplicate elements with using set()
TILL NOW I GOT THIS MUCH RESPONSES
KINDLY FILL THIS FORM AFTER YOUR EXAMS BY PRESSING
THE LINK GIVEN BELOW SO TO HELP OTHERS:
h ps://[Link]/kRPTL3uEtPMSGv5a7
IF ANY DOUBTS CONTACT WHATSAPP (9483009676)