Module Bank
___________________________________________________________________________
Subject: PROBLEM SOLVING USING PYTHON Course code: 24CS102
Year/ Sem : I/ I I Section: 25 & 28
Name of the Faculty: Dr.C. Sateesh Kumar Reddy
___________________________________________________________________________
Part-A
1. a) What will be the output of following python statements?
i) print(23+23 // 5)
ii) print(2 << 2)
iii) print(5+5 ** 3)
iv) print(5 & 4)
b) Read two integers N1 and N2, write a program to find their product
without
using multiplication (‘*’) operator and loops.
c) Write a Python program that accepts an integer (n) and computes the value
of n+nn+nnn
2. a) What is a flow control statement? Discuss if and if else statements with flow chart.
b) Write a Python program to accept n numbers from the user, store them in a list, and
compute their sum without using the built-in sum() function.
c) Write a Python program that checks the strength of a given password. The
password should meet the following criteria:
It should be at least 8 characters long.
It should contain at least one uppercase letter, one lowercase letter, one digit,
and one special character (such as @, #, $, etc.).
If the password is strong, print: "Your password is strong."
If it doesn’t meet the criteria, print: "Your password is weak."
3. Ankit has found a restaurant to have his daily meal. The restaurant provides two
menus, South meal and North meal, as shown below, and it is mandatory to order
minimum one item (one unit) from each menu. Ankit decided to spend Rs. 100 every
day for his meal. He needs to find all possible combinations of one item from South
meal and one item from North meal, such that the total price becomes less than Rs.
100.
South meal North meal
Item Price Item Price
A 10 M 25
B 15 N 15
C 30 O 40
D 45 P 15
E 40 Q 20
F 35 R 12
G 50 S 14
a) What programming concepts does Ankit need to consider while solving the
problem mentioned in the story?
b) Outline the definitive steps Rohit should take to solve the problem of finding all
possible combinations of one item from South meal and one item from North meal,
given the constraints. Design the programming constructs that would be essential for
implementing each step.
c) Design a system using Python that lists all possible combinations of items that
Ankit can order for his meal. (Example: CN, DQ, ABO, BFMQ etc.) Also, calculate
the total number of such combinations possible.
4. a) Discuss list and dictionary data structure with example for each.
b) write a python program to accept n numbers and store them in a list. Then print the
list without ODD numbers in it.
c) For a= [‘hello’, ‘how’, [1,2,3], [[10,20,30]]]
what is the output of following statement?
(i) print (a [: : ] )
(ii) print(a[-3][0])
(iii) print(a[2][ : -1])
(iv) print(a[0][ : : -1])
5. A set of Python instructions is given below.
Input = [1, 4, 7, 3, 6, 8, 2, 5, 9, 5, 4]
Result = []
for n in Input:
if n%2 == 0:
[Link](2*n**3)
else:
[Link](3*n**2)
print(Result)
a) List the different operators you observed in the code, along with their respective
categories.
b) Compute the contents of ‘Result’ after the execution and extend the above code to
find the sum of even and odd elements of ‘Result’ separately.
c) Achieve the same objective using ‘while’ loop instead of ‘for’ loop.
6. Marks of five students in three assessments are shown in the below table. Each
assessment is done for a maximum of 40 marks. To determine the final score, the two
best-performing assessments, and the average of these two scores is calculated as the
final score.
Name of student Assessment 1 Assessment 2 Assessment 3
S1 20 24 21
S2 30 32 28
S3 35 36 32
S4 32 34 36
S5 25 29 27
a) Make a list of programming concepts (variables, operators, statements, loops, data
structures, etc.) that are required to i) represent the table above and ii) calculate the
final scores for each student based on the given conditions.
b) Draw a flowchart to calculate the final scores for each student. Provide the syntax
or programming constructs that would be essential for implementing each step
c) Suppose the students who received more than 30 marks as the final score are placed
in an A+ grade. Develop a system to using Python to determine how many students
attained an A+ grade. Create a list to display the name of each student and their
respective grade. If the final score < 30, assign the grade of A.
7. a) What is a set in Python and how is it different from a list or tuple?
b) Write a Python program that accepts “n” distinct data elements from the user and
displays them as a set.
c) Write a Python program that prompts the user to input “n” unique data elements
for two separate sets, then performs and displays the results of set operations such as
union, intersection, difference, and symmetric difference
8. a) Explain how lists are updated in Python? Write a few methods that are used in
Python Lists.
b) Write a Python program to reverse a given list without using built-in functions like
reverse () or slicing ([::-1]).
c) Write a Python program to merge two lists into a single list and remove any
duplicate elements in the merged list.
9. a) Why it is necessary to have both the functions append () and extend ()?
b) Consider the list A = [9,” hi”, 7.8, 6, 5, 4, 3]. Write the Python program which
performs the following operation.
i. Insert element 10 at beginning of the list.
ii. Insert element “hello” at end of the list.
iii. Delete the element at index position -2.
iv. Apply the shift right and shift left operations on list
c) Consider a list of different data elements (strings, integers, floats, etc.), and perform
the following operations.
i. Find the length of only the string elements.
ii. Sum of integers and floats in the list.
10. a) What do you mean by data types? Explain numeric and string data type with
examples.
b) You are given a list of tuples, where each tuple consists of a student's name and
their score. Write a program that returns a list of students who scored more than 80.
c) Write a Python program that counts the number of occurrences of the character in
the given string.
PART-B
1. Four students, ‘W’, ‘X’, ‘Y’, and ‘Z’, are given a total of 100 notebooks labelled as 1,
2, …., 100. ‘W’ will get the notebooks with label numbers that are divisible by 6 but
not by 8. ‘X’ will get those divisible by 7 but not by 3. ‘Y’ will get those numbers
divisible by 11 but not by 7, and ‘Z’ will get those numbers divisible by 5 as well as
4.
a) Identify the core programming concepts that are relevant to distributing notebooks
to students W, X, Y, and Z based on the specified conditions.
b) Outline the major steps in order to design the system to distribute notebooks to
students W, X, Y, and Z based on the given conditions. Develop the programming
constructs that would be essential for implementing each step.
c) Design a system using Python so that proper distribution takes place, and display
the count of notebooks each student receives.
2. a) How does Python handle nested tuples? Can you access elements of nested tuples,
and how? Explain with example.
b) Given a tuple of mixed data types (e.g., integers, strings, and floats), write a
program
that takes an element as input and returns its index if the element exists. If the
element doesn't exist, return -1.
c) Write a Python program that takes two tuples and checks if the first tuple is a
subset
of the second one (i.e., all elements of the first tuple are present in the second
tuple). The function should return True if it is a subset, otherwise False.
3. a) Write a Python program to initialize two sets, S1 = {1, 2, 3, 4, 5} and S2 = {4, 5, 6,
7, 8}, and perform the following set operations:
i. Intersection
ii. Difference
iii. Subset
iv. Remove
b) Write a Python program that takes a list of sets as input and return a new set
containing only string elements.
c) Write a Python program that takes two sets as input and determines if they are
disjoint. (Two sets are considered disjoint if they do not share any common
elements.) The program should return True if the sets are disjoint, and False if they
are not.