Assignment


1️⃣ Lists, Tuples, Dictionaries, Sets (6 Assignments)

Assignment 1: Creating and Accessing Lists

🔹 Task: Create a list of 5 numbers and print the third element. 🔹 Example Snippet:

numbers = [10, 20, 30, 40, 50]
print("Third element:", numbers[2])  # Indexing starts from 0

Assignment 2: Modifying a List

🔹 Task: Append a new number to a list and remove an existing number. 🔹 Example Snippet:

numbers = [1, 2, 3, 4, 5]
numbers.append(6)
numbers.remove(3)
print("Updated list:", numbers)

Assignment 3: Creating and Accessing a Tuple

🔹 Task: Create a tuple with 4 strings and print the second element. 🔹 Example Snippet:

fruits = ("apple", "banana", "cherry", "date")
print("Second fruit:", fruits[1])

Assignment 4: Creating and Accessing a Dictionary

🔹 Task: Create a dictionary with name, age, and city and print the age. 🔹 Example Snippet:


Assignment 5: Modifying a Dictionary

🔹 Task: Update a dictionary key-value pair and add a new key. 🔹 Example Snippet:


Assignment 6: Creating and Using a Set

🔹 Task: Create a set, add a new element, and remove an existing element. 🔹 Example Snippet:


2️⃣ List & Dictionary Comprehensions (4 Assignments)

Assignment 7: List Comprehension (Squares of Numbers)

🔹 Task: Create a list of squares of numbers from 1 to 5 using list comprehension. 🔹 Example Snippet:


Assignment 8: List Comprehension (Even Numbers)

🔹 Task: Create a list of even numbers from 1 to 10 using list comprehension. 🔹 Example Snippet:


Assignment 9: Dictionary Comprehension (Number Squares)

🔹 Task: Create a dictionary where keys are numbers 1 to 5 and values are their squares. 🔹 Example Snippet:


Assignment 10: Dictionary Comprehension (Character Mapping)

🔹 Task: Create a dictionary mapping characters to their ASCII values for 'a' to 'e'. 🔹 Example Snippet:


3️⃣ Exception Handling (try-except-finally) (6 Assignments)

Assignment 11: Handling Division by Zero Error

🔹 Task: Handle division by zero error using try-except. 🔹 Example Snippet:


Assignment 12: Handling Multiple Exceptions

🔹 Task: Handle multiple types of exceptions (zero division and value error). 🔹 Example Snippet:


Assignment 13: Using Finally Block

🔹 Task: Use finally to always print a message after exception handling. 🔹 Example Snippet:


Assignment 14: Raising Custom Exceptions

🔹 Task: Raise a custom exception when a number is negative. 🔹 Example Snippet:


Assignment 15: Handling File Not Found Error

🔹 Task: Handle an error when trying to read a non-existent file. 🔹 Example Snippet:


Assignment 16: Nested Try-Except Blocks

🔹 Task: Use nested try-except blocks to handle different errors. 🔹 Example Snippet:


4️⃣ File Handling (reading/writing files, CSV, JSON) (4 Assignments)

Assignment 17: Writing to a File

🔹 Task: Write a message to a file named output.txt. 🔹 Example Snippet:


Assignment 18: Reading from a File

🔹 Task: Read and print the contents of output.txt. 🔹 Example Snippet:


Assignment 19: Reading a CSV File

🔹 Task: Read a CSV file and print each row. 🔹 Example Snippet:


Assignment 20: Working with JSON Files

🔹 Task: Write and read a dictionary as JSON. 🔹 Example Snippet:


Last updated