Module 03k
Module 03k
1. What is a dictionary in Python? How does it differ from lists and tuples?
2. Explain how dictionaries store key-value pairs. Provide an example.
3. What are the advantages of using dictionaries over lists?
4. How can you add, update, and delete key-value pairs in a dictionary? Provide
examples.
5. What are some common dictionary methods? Explain at least five with examples.
6. How can you check if a key exists in a dictionary? Provide a Python example.
7. What is pretty printing (pprint) in Python? How is it different from regular
printing?
8. Explain how dictionaries can be used to model real-world entities. Give an
example.
9. What is dictionary comprehension in Python? How can it be used to create a
dictionary dynamically?
10.How does Python handle dictionary iteration? How can you loop through keys,
values, and key-value pairs?
11.What are nested dictionaries? How can they be useful in structuring complex
data?
12.How does the get() method work in dictionaries? Why is it useful?
13.What happens if you try to access a dictionary key that does not exist? How can
you prevent this error?
14.Explain the concept of references in dictionaries. What happens when you
assign one dictionary to another?
15.How can dictionaries be used for counting occurrences of elements in a list?
Provide an example.
16.What are strings in Python? How are they different from lists?
17.How can you declare and initialize a string in Python?
18.What are some common string methods? Explain at least five with examples.
19.How does string concatenation work in Python? Provide different ways to
concatenate strings.
20.What is string replication? How does the * operator work with strings?
21.Explain string formatting using f-strings, format(), and % formatting.
22.What is string slicing? How can you extract substrings using indexing?
23.What are escape characters in Python strings? List some commonly used
escape sequences.
24.How can you check if a substring exists in a string? Provide a Python example.
25.Explain how the ord() and chr() functions work in Python.
26.How can the ord() function be used in encryption and character encoding?
27.What is the pyperclip module? How is it used for copying and pasting strings?
28.How can you remove whitespace from a string? Explain methods like strip(),
lstrip(), and rstrip().
29.What is the difference between split() and join() methods in Python?
30.Explain the Multi-Clipboard Automatic Messages project. How does it use
pyperclip for automation?
1. Scenario: You are designing an employee database system using dictionaries.
The program should:
○ Store employee details (name, age, department, salary).
○ Allow updating an employee’s salary.
○ Retrieve and display details of an employee by their name.
Question: Implement this using a Python dictionary and explain how
key-value pairs are useful in storing structured data.
2. Scenario: A library management system keeps track of books using a
dictionary where:
○ The key is the book title, and the value is the availability status
("Available" or "Issued").
○ Users can check if a book is available.
○ The system updates the status when a book is issued or returned.
Question: Write a Python program for this and explain how dictionaries
help in data retrieval.
3. Scenario: A student marks system stores student names as keys and their
marks as values in a dictionary.
○ Allow adding new students and marks.
○ Calculate the average marks of all students.
Question: Implement this using dictionaries and explain how iteration
over key-value pairs works.
4. Scenario: You are designing a voting system where:
○ A dictionary stores candidates as keys and their vote counts as values.
○ When a user votes, the count for the chosen candidate increases.
○ The program displays the winner at the end.
Question: Write a Python program for this and explain how dictionaries
efficiently store real-world data.
5. Scenario: A supermarket billing system stores product details in a dictionary.
○ The dictionary contains product names as keys and prices as values.
○ A user selects products and their quantities.
○ The program calculates the total bill.
Question: Implement this and explain how dictionaries simplify data
organization in real-world applications.
Scenario-Based Questions on Manipulating Strings
a) "None"
b) "Not Found"
c) "city"
d) Error
Answer: b) "Not Found"
print(d.keys())
4. Which method is used to remove a specific key-value pair from a dictionary?
a) delete()
b) pop()
c) remove()
d) discard()
Answer: b) pop()
5. What will be the output of the following Python code?
my_dict = {"x": 5, "y": 10}
my_dict["x"] += 1
print(my_dict["x"])
a) 5
b) 6
c) 10
d) Error
Answer: b) 6
a) "HELLO"
b) "hello"
c) "Hello"
d) Error
Answer: a) "HELLO"
a) "Python Programming"
b) "PythonProgramming"
c) "Python + Programming"
d) Error
Answer: b) "PythonProgramming"
print(s.replace("World", "Python"))
a) "Hello, Python!"
b) "Hello, World!"
c) "Hello Python"
d) "Hello, World"
Answer: a) "Hello, Python!"
a) 1
b) 0
c) -1
d) "e"
Answer: a) 1
pyperclip.copy("Hello")
print(pyperclip.paste())
a) "Hello"
b) None
c) Error
d) Empty String
Answer: a) "Hello"
a) "hello"
b) "Hello"
c) "HELLO"
d) "hELLO"
Answer: b) "Hello"