Week7 Lab Q
Week7 Lab Q
Problem Statements
1. Event Attendance:
A school has two events, and the attendees are stored in two sets. Create 2 sets
with names of students. Write a program to:
You are given a dictionary containing student names as keys and their marks as
values.
students = {
"Rohan": 85,
"Spoorthi": 90,
"Aditi": 78,
"Tanya": 92
3. Sentence Analysis:
4. Given a string, count the number of occurrences of each character and store the result in
a dictionary.
Example Input:
"hello world"
Expected Output:
{'h': 1, 'e': 1, 'l': 3, 'o': 2, ' ': 1, 'w': 1, 'r': 1, 'd': 1}
5. Merge two dictionaries into one. If a key appears in both dictionaries, the value in the
second dictionary should overwrite the one in the first.
Example Input:
dict1 = {'a': 1, 'b': 2}
dict2 = {'b': 3, 'c': 4}
Expected Output:
{'a': 1, 'b': 3, 'c': 4}
6. You work at a movie theater that keeps track of daily bookings. Each booking
record contains the customer's name, selected movie, and seat number in a specific
format. The theater needs to analyze these booking records to manage seating and
prevent duplicate bookings. Take input from the user.
Hints:
7. Password Validator
● Be 8 characters long
● Must contain 1 Upper case character, 1 lower case character and 1 number
● If valid return valid password if not print invalid
8. Given a dictionary where values are unique, swap the keys and values.
Example Input:
{'one': 1, 'two': 2, 'three': 3}
Expected Output:
{1: 'one', 2: 'two', 3: 'three'}
9. You are given a list of student names and a corresponding list of their scores. Create a
dictionary that categorizes the students into three groups: "Excellent" (score 80 and
above), "Good" (score between 60 and 79), and "Needs Improvement" (score below 60).
Output the dictionary with the categories as keys and lists of student names as values.
Steps to Solve:
1. Create an empty dictionary with the keys: "Excellent", "Good", and "Needs
Improvement".
2. Iterate through the list of students and their scores.
3. Based on the score, categorize each student and append their name to the corresponding
list in the dictionary.
Example Input:
Expected Output:
Solution Explanation:
10. Take a dictionary with product names as keys and prices as values. Print each product
and its price. If the price is more than $20, add a message: "Expensive".
11. Create a program that generates a list of common elements between two sets, but only if
those elements are divisible by both 2 and 3. Print the final list of common elements.
Example Input:
set1 = {2, 3, 6, 12, 15, 18, 20, 24}
set2 = {1, 6, 12, 18, 24, 30, 36}
Example Output:
[6, 12, 18, 24]
12. Given a list of numbers, create a new list where each element is the sum of all elements
from the original list except itself. For example, given [1, 2, 3, 4], the output should be [9,
8, 7, 6].
13. Write a program that takes a string as input and extracts all the unique consonants from
the string. Store the consonants in a set to ensure each consonant is unique. If no
consonants are found, print "No consonants found". Consonants are defined as
alphabetic characters that are not vowels (a, e, i, o, u, case-insensitive).
Example Input 1:
string = "OpenAI"
Example Output 1:
{'p', 'n'}
14. Given a dictionary of product prices, find and print the product with the highest price. If
there is a tie, print all products with the highest price.
Department of CSE, PES University
UE24CS151A-Python for Computational Problem Solving
Laboratory Week 7
products = {
"Laptop": 1200,
"Smartphone": 800,
"Tablet": 1200,
"Headphones": 150
}
"Smartphone": 800,
"Tablet": 1200,
"Headphones": 150
}