Assignment For Essential of Python
Assignment For Essential of Python
Question 2: Given a code snippet using a try-except block, identify the purpose of this block
and explain how it handles potential errors.
Question 3: Enumerate and describe at least five common types of exceptions in Python.
Provide examples of scenarios where each type might occur.
Question 4: Explain the difference between ‘r’, ‘w’, and ‘a’ file modes in Python. Provide
examples for each mode and describe how you would handle a ‘FileNotFoundError’
exception while working with files in ‘r’ mode.
Question 5: Demonstrate the usage of the ‘with’ statement in file handling. Explain how it
ensures proper file closure and exception handling, comparing it to the traditional way of
opening and closing files manually.
Question 7: Explain the concept of generators and how they differ from regular functions in
Python. Provide an example of a generator functions with lists or iterables, and explain their
return values and usage in logical operations.
Question 8: Write a Python function that takes a list of integers as input and returns a new list
containing only the even numbers from the original list using list comprehension. Ensure the
function has a default parameter to handle empty input lists. Demonstrate the function by
providing an example.
P.T.O
Question 9: Create a Python program that simulates a simplified version of a Google Form
using Tkinter. Include components such as labels, entry widgets for user input, check buttons
for multiple-choice options, and a submit button. Upon clicking the submit button, display the
collected information in the console.
Question 10: Create a Python program that interacts with an SQLite database. Define a table
named 'Employees' with columns for 'id' (integer), 'name' (text), 'age' (integer), and 'salary'
(real). Perform the following operations:
Question 11: Create a Python-based chat application where multiple clients can connect to a
central server to exchange messages.
➢ Design a server program that listens on a specific port for incoming connections from
clients and manages the chat functionality.
➢ Develop a client program that can connect to the chat server, send messages, and
receive messages from other connected clients.
➢ Ensure that messages from each client are broadcasted to all other connected clients.
Question 12: How do Python's 'filter', 'map', and 'reduce' functions work with examples, and
what role do decorators play in modifying their behavior? Additionally, explain the concept
and usage of frozen sets in Python.
Question 13: Could you explain how regular expressions in Python can be used to split
strings, handle special characters, validate dates and emails, utilize quantifiers, and
differentiate between 'match' and 'findall methods in regex with suitable examples?
Question 14: Write a Python code snippet that defines three tasks as separate functions and
assigns each task to a thread using the 'threading module. Additionally, demonstrate how you
would handle multi-threading and synchronization issues within these tasks.
Question 15: Describe how you would access the Facebook Messenger API using Python,
outlining the essential steps to authenticate and send messages through the API. Provide a
code snippet demonstrating the process.
P.T.O