1. Write a Python program that demonstrates key removal builtin methods.
Explain how each
method manipulates the dictionary.
2. Write a Python program to manage a simple library system using a dictionary. The program
should allow you to:
(a) Add a new book with its title and quantity.
(b) Update the quantity of an existing book.
(c) Search for a book by title.
(d) Remove a book from the library.
(e) Display the entire collection.
3. Create a Python program to track student grades using a dictionary. The program should:
(a) Store student names as keys and their list of grades as values.
(b) Add a new student along with their grades.
(c) Update grades for an existing student.
(d) Calculate and display the average grade for a given student.
(e) List all students who have an average grade above 75.
4. Write a python program to perform the following:
1. add members to a dictionary
2. concatenate two dictionaries
3. sort the dictionary by values
5. Write a Python program to use dictionary functions and methods. The program should:
[Link] a dictionary called my_dict with some key-value pairs.
[Link] the len() function to print the number of key-value pairs in my_dict.
[Link] the max() function to print the maximum value in my_dict.
[Link] the min() function to print the minimum value in my_dict.
6. (i)Python program to sort a dictionary by value
(ii)Python program to concatenate the following dictionaries and to create a new one
• Dict1= {1:10,2:20}
• Dict2={3:30.4:40}
(iii)Python program to add members to a Set.
7. Describe Python dictionary built-in methods (any 6) in detail. Give an example program for
each.
8. Build a Python program and perform the following operations using dictionary.
i) Convert lists into a dictionary in a way that item from list1 is the key and item from list2 is
the value.
ii) Merge two Python dictionaries into one.
iii) Delete a list of keys from a dictionary.
v) Check if a value exists in a dictionary.
9. a. Write a Python program to sort a dictionary by value.
b. Given person = {'name': 'John', 'age': 25}, what happens if you try to access
person['gender']? Explain the reason.
c. Given data = {'x': 10, 'y': 20, 'z': 30}, analyze the effect of the statement data['x'] +=
data['y']. What will be the new value of 'x'?
10. Write a Python program to manage course enrollments using sets. The program should
perform the following operations:
Create two sets: one for students enrolled in 'Python Programming' and another for 'Data
Science'.
Find and display the list of students enrolled in both courses.
Display students who are enrolled only in 'Python Programming'.
Display the total number of unique students enrolled across both courses.
Check whether a particular student (entered by the user) is enrolled in either course."
Use appropriate set operations and methods like intersection(), difference(), union(), and in to
complete the tasks.
11. A university is tracking student enrollments in two popular certification courses: "Python
Programming" and "Data Science". Each course maintains a list of enrolled students. Your
task is to help the administration analyze enrollment data using Python sets.
Tasks:
Create two sets:
python_students: containing names of students enrolled in Python Programming.
data_science_students: containing names of students enrolled in Data Science.
Write a Python program to perform the following operations using set methods:
a. Display the names of students who are enrolled in both courses.
b. List the students who are enrolled only in Python Programming.
c. List the students who are enrolled only in Data Science.
d. Show the total number of unique students enrolled in either course.
e. Accept a student name as input and check if the student is enrolled in any course. Display
an appropriate message.
12. Write a Python program using the re module to:
(a) Validate Email Addresses:
Check if the entered email address matches the format: username@[Link]
(Example: user123@[Link])
(b) Validate Mobile Numbers:
Ensure the mobile number has exactly 10 digits and starts with 7, 8, or 9.
(c) Validate Postal Codes:
Accept only 6-digit Indian postal codes that don’t start with 0.
Extract all valid email addresses from a paragraph of text entered by the user.
Explain how regular expressions improve input validation, and compare their use to
traditional string methods.
13. Write a Python program to demonstrate the following characteristics of sets:
- Unordered collection of unique elements
- Mutability
- Hashability
- Support for mathematical operations
14. Write a Python program to compute the difference of two sets using the following methods:
[Link] the difference() method
[Link] the - operator
[Link] a loop to iterate over the elements of both sets
15. The institution has given internet access to all students through a web portal that allows
internet usage only by entering username and password. It is found that the password is not
highly secure as many of them have simple password (example: 1234). To overcome this and
enhance secured internet usage the institution is expecting to display the strength of password
upon first login. Write a Regular expression the checks the password strength and displays as
weak, good and strong.
16. Outline the basic operations of python sets in detail. Given an example program for each.
17. Write a Python program to compare two sets representing students enrolled in two different
courses:
(i) Find and display students enrolled in both courses (intersection).
(ii) Find students who are enrolled only in the first course (difference).
(iii) Find students who are enrolled only in one course (symmetric difference).
(iv) Display whether one course’s enrollment is a subset of the other
18. Discover a Python programs for the follwing scenarios using Regular Expressions.
i)Write a Python function that takes an email address as input and uses regular expressions to
validate whether it follows the standard email format.
ii)Write a Python function that takes a text string as input and extracts all valid phone
numbers using regular expressions.