0% found this document useful (0 votes)
5 views4 pages

Python - Module Bank - T1 - PA

The document outlines a problem-solving module using Python, detailing various programming tasks and concepts for students. It includes exercises on flow control, data structures, and algorithms, along with practical programming assignments related to calculations, list manipulations, and set operations. The document serves as a comprehensive guide for students to enhance their Python programming skills through hands-on practice.

Uploaded by

simomobigmonya
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)
5 views4 pages

Python - Module Bank - T1 - PA

The document outlines a problem-solving module using Python, detailing various programming tasks and concepts for students. It includes exercises on flow control, data structures, and algorithms, along with practical programming assignments related to calculations, list manipulations, and set operations. The document serves as a comprehensive guide for students to enhance their Python programming skills through hands-on practice.

Uploaded by

simomobigmonya
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

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.

You might also like